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: Unable to access jarfile under Cygwin #20

Closed
Lucas-C opened this issue Jul 13, 2016 · 6 comments
Closed

Error: Unable to access jarfile under Cygwin #20

Lucas-C opened this issue Jul 13, 2016 · 6 comments

Comments

@Lucas-C
Copy link
Contributor

Lucas-C commented Jul 13, 2016

Hello,

I'm trying to write a pre-commit hook to do some HTML validation using your lib:
Lucas-C/pre-commit-hooks@2916a99

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
Copy link
Contributor Author

Lucas-C commented Jul 13, 2016

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
Copy link
Contributor Author

Lucas-C commented Jul 13, 2016

Some more findings:

  • the error only show up when the path to vnu.jar passed to java -jar is an absolute one
  • if the path to the checked HTML is absolute, the validation will fail silently

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
Copy link
Contributor Author

Lucas-C commented Jul 13, 2016

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

@Lucas-C Lucas-C changed the title Error: Unable to access jarfile Error: Unable to access jarfile under Cygwin Jul 13, 2016
@lorvent
Copy link

lorvent commented Feb 13, 2019

@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
Copy link
Contributor Author

Lucas-C commented Feb 13, 2019

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
Copy link

lorvent commented Feb 13, 2019

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"'

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

3 participants