neuland / pug4j

a pug implementation written in Java (formerly known as jade)
MIT License
61 stars 12 forks source link

extends file location not correctly resolved on linux #3

Closed codemonstur closed 3 years ago

codemonstur commented 3 years ago

When using this code:

public static void main(final String... args) throws IOException {
    final Path path = Paths.get("src/main/resources/page.pug");
    System.out.println(path.toAbsolutePath().toString());
    final String html = Pug4J.render(path.toAbsolutePath().toString(), new HashMap<String, Object>());
    System.out.println(html);
}

And referring to this path using extends: ../include/skeleton.pug. I get this error on debian (running in windows):

$ java -jar target/pug-1.jar
/mnt/c/Projects/test/pug/src/main/resources/page.pug
Exception in thread "main" class de.neuland.pug4j.exceptions.PugParserException: The template [../include/skeleton.pug] could not be opened. Maybe it is located outside the base path?
mnt/c/Projects/test/pug/src/main/include/skeleton.pug (No such file or directory) in /mnt/c/Projects/test/pug/src/main/resources/page.pug:1
    at de.neuland.pug4j.parser.Parser.createParser(Parser.java:633)
    at de.neuland.pug4j.parser.Parser.parseExtends(Parser.java:600)
    at de.neuland.pug4j.parser.Parser.parseExpr(Parser.java:124)
    at de.neuland.pug4j.parser.Parser.parse(Parser.java:79)
    at de.neuland.pug4j.Pug4J.createTemplate(Pug4J.java:105)
    at de.neuland.pug4j.Pug4J.getTemplate(Pug4J.java:90)
    at de.neuland.pug4j.Pug4J.render(Pug4J.java:35)
    at de.neuland.pug4j.Pug4J.render(Pug4J.java:31)
    at pug.Main.main(Main.java:15)

Full code example can be found here: https://github.com/codemonstur/pug4j-bug Problem does not occur with Jade4J.

chbloemer commented 3 years ago

I setup some more testcases for the static PUG4J API and resolved some issues with file path handling. Please try 2.0.0-alpha4

codemonstur commented 3 years ago

Yes it now loads the extends file. I did notice however that when I call Pug4J.render(fullPath, new HashMap<>()); with a path that doesn't exist I get an NPE:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "de.neuland.pug4j.template.TemplateLoader.getReader(String)" because "this.templateLoader" is null
  at de.neuland.pug4j.exceptions.PugException.getTemplateLines(PugException.java:92)
  at de.neuland.pug4j.exceptions.PugException.createErrorMessage(PugException.java:58)
  at de.neuland.pug4j.exceptions.PugException.toString(PugException.java:106)
  at java.base/java.lang.String.valueOf(String.java:3367)
  at java.base/java.io.PrintStream.println(PrintStream.java:1047)
  at java.base/java.lang.Throwable$WrappedPrintStream.println(Throwable.java:764)
  at java.base/java.lang.Throwable.printStackTrace(Throwable.java:671)
  at java.base/java.lang.Throwable.printStackTrace(Throwable.java:660)
  at java.base/java.lang.Throwable.printStackTrace(Throwable.java:651)
  at pug.Main.main(Main.java:23)
christophbloemer0382 commented 3 years ago

Please check alpha-5. There should be a FileNotFoundException now.

codemonstur commented 3 years ago

Yes it throws a FileNotFoundException now. Great!