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

Question related to HTL rules #235

Open
anrayt opened this issue Apr 24, 2023 · 2 comments
Open

Question related to HTL rules #235

anrayt opened this issue Apr 24, 2023 · 2 comments
Labels
enhancement help wanted htl Issues related to HTL language

Comments

@anrayt
Copy link

anrayt commented Apr 24, 2023

Hey, folks!
I'd wish to discuss some rules related to HTL which is not clear to me
"
HTL-6 HTL automatically recognises the context for HTML output

HTL uses uri display context as default for src, poster, manifest, href, formaction, data, cite, action attributes
HTL-7 Style and script tags display context definition is mandatory
"
Let me share an example:
<script type="text/javascript" src="${'{0}/some-js-file.js' @ format = [inheritedPageProperties.someProperty]}"></script>
There is a major issue with the rule HTL-7 - no context is provided with a script tag.
Okay, I'll fix it by adding context='uri' because it's actually an uri.
But, after that, one more issue will be here: HTL-6 - HTL uses uri display context as default for src .
To fix that, I changed the context to - context='attribute'.
It also looks ok to me, but maybe you could clarify a little bit about how it's expected to be used correctly.
Thanks in advance,
Anton

@toniedzwiedz
Copy link
Collaborator

Hi @anrayt, l believe HTL-7 was intended as a check for literals, i.e. verbatim JavaScript and CSS code being output. The VIOLATION_MESSAGE seems to confirm that.

Looking at the implementation https://github.com/wttech/AEM-Rules-for-SonarQube/blob/master/src/main/java/com/cognifide/aemrules/htl/checks/ScriptsAndStyleMandatoryDisplayContextCheck.java#L69, the rule applies to all expressions within a <script> tag, even when it's inside an src attribute.

In your situation, I'd keep the code as-is, with the implicit, default display context on the src attribute, and mark the violation of HTL-7 as a false positive/won't fix.

The rule could use an improvement.

@toniedzwiedz toniedzwiedz added enhancement help wanted htl Issues related to HTL language labels May 5, 2023
@anrayt
Copy link
Author

anrayt commented May 12, 2023

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted htl Issues related to HTL language
Projects
None yet
Development

No branches or pull requests

2 participants