Skip to content

Modular Input - textInNode throwing exception when input string is empty #122

Description

@segfault-

Version of this project you're using 1.6.4
Platform version osx 10.13.3 (high sierra)
Framework version java 1.8.0_131
Splunk version 7.0.2 - 03bbabbd5c0f

Other relevant information (ex: local/remote environment, Splunk network configuration)

I tracked down this bug because at surface level, it appeared that input validation was not being executed. Indeed it wasn't being executed because XmlUtil.textInNode would throw an exception when encountering an argument with a null/empty value.

I have a proposed fix below that seems to work on 7.0.2, but i can't speak to backwards compatibility with older versions of splunk

com.splunk.modularinput.XmlUtil.textInNode(XmlUtil.java:38)\com.splunk.modularinput.Parameter.nodeToParameterList(Parameter.java:72)\com.splunk.modularinput.ValidationDefinition.parseDefinition(ValidationDefinition.java:245)\com.splunk.modularinput.Script.run(Script.java:85)\com.splunk.modularinput.Script.run(Script.java:44)...

fix in my env
static String textInNode(Node node, String errorMessage) throws MalformedDataException {
Node child = node.getFirstChild();

  •    if (child.getNodeType() != Node.TEXT_NODE) {
    
  •        throw new MalformedDataException(errorMessage);
    
  •    } else {
    
  •        return ((Text)child).getData();
    
  •    if(child != null) {
    
  •       if (child.getNodeType() != Node.TEXT_NODE) {
    
  •           throw new MalformedDataException(errorMessage);
    
  •       } else {
    
  •           return ((Text)child).getData();
    
  •       }
       }
    
  •    return("");
    
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions