Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on evaluating code starting with "do" #36

Closed
lgomezm opened this issue Feb 7, 2018 · 2 comments
Closed

Error on evaluating code starting with "do" #36

lgomezm opened this issue Feb 7, 2018 · 2 comments

Comments

@lgomezm
Copy link

lgomezm commented Feb 7, 2018

When a sandbox instance is created and it disallows no-braces, it throws an exception when the JS code to evaluate starts with any of { function, for, while, do }. Basically, the exception's stacktrace says:

Exception in thread "main" delight.nashornsandbox.exceptions.BracesException: No block braces after function|for|while|do
	at delight.nashornsandbox.internal.JsSanitizer.checkBraces(JsSanitizer.java:177)
	at delight.nashornsandbox.internal.JsSanitizer.secureJs(JsSanitizer.java:220)
	at delight.nashornsandbox.internal.NashornSandboxImpl.eval(NashornSandboxImpl.java:129)
	at delight.nashornsandbox.internal.NashornSandboxImpl.eval(NashornSandboxImpl.java:104)
        ...

It looks like the block braces pattern matching makes it fail whenever the text starts with do. This code can reproduce the issue:

public static void main(String[] args) throws ScriptException {
        NashornSandbox sandbox = NashornSandboxes.create();
        sandbox.setMaxCPUTime(100);
        sandbox.setMaxMemory(1000 * 1000);
        sandbox.allowNoBraces(false);
        ExecutorService executor = Executors.newSingleThreadExecutor();
        sandbox.setExecutor(executor);
        Boolean done = (Boolean) sandbox.eval("done = false;");
        System.out.println(done);
}
mxro pushed a commit that referenced this issue Feb 7, 2018
mxro pushed a commit that referenced this issue Feb 7, 2018
@mxro
Copy link
Collaborator

mxro commented Feb 7, 2018

Thank you for reporting this issue!

It is fixed in version 0.1.9 which should be available in Maven Central shortly.

Please let me know if this fixes it for you or if there are any other issues!

@lgomezm
Copy link
Author

lgomezm commented Feb 8, 2018

I can confirm it now works. Thanks, Max.

@lgomezm lgomezm closed this as completed Feb 8, 2018
Frontrider pushed a commit to Frontrider/delight-nashorn-sandbox that referenced this issue Mar 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants