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

Off by one error in package parsing code leads to template compilation errors #598

Open
mvitaly opened this issue Aug 1, 2023 · 0 comments

Comments

@mvitaly
Copy link
Contributor

mvitaly commented Aug 1, 2023

Describe the bug
When the temp dir is set to a path that starts with a reserved word (/var/folders/... which is the default on OSX) the template compilation step fails with an exception similar to:

org.fusesource.scalate.CompilerException: Compilation failed:
:2.9 identifier expected but 'var' found.
package var.folders....
        ^
	at app//org.fusesource.scalate.TemplateEngine.compileAndLoad(TemplateEngine.scala:857)
	at app//org.fusesource.scalate.TemplateEngine.compileAndLoadEntry(TemplateEngine.scala:725)
	at app//org.fusesource.scalate.TemplateEngine.liftedTree1$1(TemplateEngine.scala:436)
	at app//org.fusesource.scalate.TemplateEngine.load(TemplateEngine.scala:430)
	at app//org.fusesource.scalate.TemplateEngine.load(TemplateEngine.scala:485)
	at app//org.fusesource.scalate.TemplateEngine.layout(TemplateEngine.scala:582)
...

To Reproduce
Can be reproduced using the following code:

val engine = new TemplateEngine
val source = TemplateSource.fromFile("/var/tmp2/foo.ssp")
source.engine = engine
assertResult("tmp2") { source.packageName }  // will be "var.tmp2" instead

Expected behavior
The compilation of the template should not fail.

Desktop (please complete the following information):

  • OS: Mac OSX

This seems to be caused by an off by one error in extractPackageAndClassNames method of TemplateSource trait.
Will submit a PR.

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

1 participant