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

[yesod-test] htmlNoneContain function fails to accurately evaluate contained strings within HTML #1799

Open
jlgalarza3 opened this issue Apr 11, 2023 · 1 comment

Comments

@jlgalarza3
Copy link

Using yesod-test-1.6.15

The htmlNoneContain function in Yesod's testing library is intended to evaluate the presence or absence of a given string within a specified HTML element. However, it currently includes the values and attributes within that element in its evaluation, which can lead to inaccurate results in certain cases.

For example, if I call htmlNoneContain "td" "S3" on the following HTML snippet:

<td>
    <form action="/addToken" method="post">
        <input type="hidden" name="_token" value="mS3">
        <div>
            S1
        </div>
        </input>
    </form>
</td>

The test fails, even though the string "S3" does not appear anywhere within the text content of the td element. This is because there is a value attribute within the input element that contains the string "S3".

I wanted to ask if this is the intended behavior of the function, or if there is a way to exclude the contents of attributes and take into account only the text content of the element.

Thank you for your attention to this matter!

@schoettl
Copy link
Contributor

I guess it's intended that these functions check for HTML code, not for text content.

E.g. htmlAnyContain "input" "type=" should also be True because Data.List.isInfixOf is used on the result of htmlQuery which is just type ByteString (i.e. plain HTML code).

Maybe the documentation should be more precise on that.

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

2 participants