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

Windows path slash in template #730

Open
lindgrenfredrik opened this issue Feb 27, 2020 · 0 comments
Open

Windows path slash in template #730

lindgrenfredrik opened this issue Feb 27, 2020 · 0 comments

Comments

@lindgrenfredrik
Copy link

Hi,

Have a issue with trying to get handlebar template to work in generating correct output for windows paths.

Example:

testline1: {{src_folder}} {{src_subfolder}}
testline2: {{src_folder}}{{src_subfolder}}
testline3: {{src_folder}}\{{src_subfolder}}

If I read above data from a file and put it as a single string into handlebars.compileInline() function and then provide context with values for src_folder and src_subfolder to template.apply call

I get correct output with both parameters resolved on line 1
I get expected behavior on line 2 with only first parameter resolved and then escaped value of {{src_subfolder}}

Problem occurs on line 3, where it gives same result as on line 2 with single \ and {{src_subfolder}} string.
I expect it to be both parameters resolved with single \ in between

Tried with 4.1.2 and 4.0.7 versions

If I try it online at http://tryhandlebarsjs.com/
I get the behavior I expect for line 3 (line 1 & 2 are same as for handlebars.java)

Simple java main function I used to test this (file1.handlebars contains example data above):

public static void main(String[] args) throws Exception {
System.out.println("Output testjknack");
Map<String, Object> bundle = new HashMap<String, Object>();
bundle.put("src_folder", "folder");
bundle.put("src_subfolder", "subfolder");
Context context = Context
.newBuilder(bundle)
.resolver(
MapValueResolver.INSTANCE,
JavaBeanValueResolver.INSTANCE,
FieldValueResolver.INSTANCE)
.build();

    String test1 = new String(Files.readAllBytes(Paths.get("file1.handlebars")));

    Handlebars handlebars = new Handlebars();
    Template template = handlebars.compileInline(test1);
    System.out.println("Output of template1: " + template.apply(context));
}
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