svenkreiss / html5validator

Command line tool to validate HTML5 files. Great for continuous integration.
MIT License
323 stars 34 forks source link

Error: Unable to access jarfile under Cygwin #20

Closed Lucas-C closed 8 years ago

Lucas-C commented 8 years ago

Hello,

I'm trying to write a pre-commit hook to do some HTML validation using your lib: https://github.com/Lucas-C/pre-commit-hooks/commit/2916a991f2d2d838dc4931a442d68af58ac73d68

However I'm facing this error when using html5validator.validator.Validator:

Error: Unable to access jarfile /home/lucas_cimon/.pre-commit/repor9ky908h/py_env-default/lib/python3.4/site-packages/vnujar/vnu.jar

I replicated this issue by invoking the command directly:

$ java -jar /home/lucas_cimon/.pre-commit/repor9ky908h/py_env-default/lib/python3.4/site-packages/vnujar/vnu.jar vignette.hbs
Error: Unable to access jarfile /home/lucas_cimon/.pre-commit/repor9ky908h/py_env-default/lib/python3.4/site-packages/vnujar/vnu.jar

Note that I'm working under Windows with Cygwin. A StackOverflow answer to this issue suggested to move the jar in my current directory, and it does work when I invoke it manually:

$ java -jar vnu.jar vignette.hbs                                                            "file:/G:.../vignette.hbs":1.1-2.72: error: Start tag seen without seeing a doctype first. Expected “<!DOCTYPE html>”.
"file:/G:/.../vignette.hbs":1.1-2.72: error: Element “head” is missing a required instance of child element “title”.
"file:/G:/.../vignette.hbs":1.1-2.72: error: Bad value “{{offer.url}}” for attribute “href” on element “a”: Illegal character in path segment: “{” is not allowed.
"file:/G:/.../vignette.hbs":5.9-5.66: error: Bad value “{{imgSrc}}” for attribute “src” on element “img”: Illegal character in path segment: “{” is not allowed.

Would you have any explanation for this strange problem ? I'm going to try to modify html5validator/validator.py locally to change the current directory before the .jar invocation.

Lucas-C commented 8 years ago

Nope. Adding a os.chdir(os.path.dirname(self.vnu_jar_location)) before line 83 did not change a thing: https://github.com/svenkreiss/html5validator/blob/master/html5validator/validator.py#L83

Lucas-C commented 8 years ago

Some more findings:

In Cygwin, converting the absolute Unix paths to Windows ones fixes the problem:

$ java -jar "$(cygpath -w /home/lucas_cimon/.pre-commit/repor9ky908h/py_env-default/lib/python3.4/site-packages/vnujar/vnu.jar)" "$(cygpath -w /home/lucas_cimon/vignette.hbs)"
Lucas-C commented 8 years ago

I submitted a PR with a suggestion for fix. I tested it, it fixes my initial issue.

lorvent commented 5 years ago

@Lucas-C can you tell me how did you fix "file:/G:/.../vignette.hbs":1.1-2.72: error: Bad value “{{offer.url}}” for attribute “href” on element “a”: Illegal character in path segment: “{” is not allowed.

i use template engines so it is throwing same error to me aswell.

Lucas-C commented 5 years ago

I implemented various strategies to remove mustaches in my git pre-commit hook: https://github.com/Lucas-C/pre-commit-hooks-java/blob/master/pre_commit_hooks/validate_html.py#L33

lorvent commented 5 years ago

ok.... I use laravel with blade syntax, so finally i had to use it like this

- html5validator --root resources/views/ --match "*.blade.php" --blacklist node_modules vendors src --ignore-re 'Bad value "{{\s?asset|route|url(.*?)\s?}}" for attribute "href|src" on element "link|script|img|a"' 'Bad value "{{\s?asset|route|url(.*?)\s?}}" for attribute "action" on element "form"' 'Bad value "{{\s?URL::to(.*?)\s?}}" for attribute "action" on element "form"' 'Non-space characters found without seeing a doctype first. Expected "<!DOCTYPE html>"' 'Element "head" is missing a required instance of child element "title"'