Skip to content

rhino drops a character on single line comments #2151

@kingthorin

Description

@kingthorin

Rhino 1.8.0 (I haven't checked older versions)

PoC:

    public static void main(String[] args) {
        try {
            CompilerEnvirons env = new CompilerEnvirons();
            env.setRecordingComments(true);
            Parser parser = new Parser(env, env.getErrorReporter());
            String comment = "// comment";
            System.out.println(comment);
            AstRoot ast = parser.parse(comment, null, 1);
            System.out.println(comment.length());
            System.out.println(ast.debugPrint());
            ast.getComments().forEach(comm -> System.out.println(comm.getValue()));
        } catch (EvaluatorException ee) {
                // nothing to do
        }
    }

Output:

// comment
10
0	SCRIPT 0 9
0	  COMMENT 0 9
0	  COMMENT 0 9

// commen

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions