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

Vale incorrectly detects issues inside <pre> tag ONLY if token first appears outside of <pre> tag #661

Closed
1 task done
adish-jain opened this issue Jul 26, 2023 · 3 comments

Comments

@adish-jain
Copy link

adish-jain commented Jul 26, 2023

Check for existing issues

  • Completed

Environment

OS - MacOS
Install Method - Homebrew
Vale Version - 2.25.2

Describe the bug / provide steps to reproduce it

I've got a real head scratcher here @jdkato, hoping you can help me think through what might be going on here.

I'm noticing a really strange bug where a <pre> tag nested within a <li> tag is flagging tokens within the <pre> scope, but only if that same token occurs prior to the <pre> tag and within the <li>.

Here's an example demonstrating what I mean -- let's say I'm running Vale over the following content and I have a rule configured which flags the usage of "TAM". In this scenario, I have no specific scopes set for this rule, but I am using the default skippedScopes to ignore the pre scope in my vale.ini:

{
"content": "<div><li>To calculate the TAM, first do this<pre>x = 1\ny = 1\nz = x + y\nnow that have z, we can find the value\nTAM would be equal to z</pre></li></div>"
}

The response I would expect would be that the first usage of "TAM" gets flagged (the one within the <li> but prior to the <pre>).

However, this is the response that is getting returned is flagging the usage of "TAM" within the <pre> tag and NOT the one within the <li> tag but prior to the <pre>:

{
    "styleChecks": {
        "stdin.html": [
            {
                "Action": {
                    "Name": "Acronyms",
                    "Params": null
                },
                "Span": [
                    1,
                    3
                ],
                "Check": "Acronyms",
                "Description": "",
                "Link": "/style/acronyms",
                "Message": "'TAM' has no definition",
                "Severity": "warning",
                "Match": "TAM",
                "Line": 5
            }
        ]
    }
}

It's super strange to me that it's flagging one and not the other. What's even more strange is that if the first usage of "TAM" did not exist (the one outside the <pre> tag), then the second usage of "TAM" (the one inside the <pre> tag) would not get flagged.

In summary, to reproduce the following needs to be true:

  1. The <pre> tag is nested within a <li> tag
  2. Use the offending token outside the <pre> tag but inside the <li> tag
  3. Re-use the offending token inside the <pre> tag too

And the result will be that the offending token gets flagged within the <pre> tag but not elsewhere. Interestingly, I've also noticed that this only occurs when the offending token is on the last line of the <pre> tag. For example:

{
"content": "<div><li>To calculate the TAM, first do this<pre>x = 1\ny = 1\nz = x + y\nnow that have TAM z, we can find the value\nwould be equal to z</pre></li></div>"
}

The above input works exactly as expected, flagging the first usage of "TAM", because the usage of "TAM" inside the <pre> tag is not in the last sentence.

For reference, here is the skippedScopes I have configured: SkippedScopes = alt, script, style, pre, figure.

@jdkato
Copy link
Member

jdkato commented Aug 15, 2023

This is not valid HTML, so features like SkippedScopes may not work.

@jdkato jdkato closed this as completed Aug 15, 2023
@adish-jain
Copy link
Author

Hey @jdkato thanks for getting back to me. To be clear, the part I run the style checks on is only the value of the content key, which is valid HTML:

<div><li>To calculate the TAM, first do this<pre>x = 1\ny = 1\nz = x + y\nnow that have z, we can find the value\nTAM would be equal to z</pre></li></div>

So I would expect SkippedScopes to work.

@jdkato
Copy link
Member

jdkato commented Aug 15, 2023

That is not valid HTML. There are many online validators you can use to confirm this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants