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] bring back support for matching of preescaped strings #1784

Open
eahlberg opened this issue Oct 7, 2022 · 4 comments · May be fixed by #1786
Open

[yesod-test] bring back support for matching of preescaped strings #1784

eahlberg opened this issue Oct 7, 2022 · 4 comments · May be fixed by #1786

Comments

@eahlberg
Copy link
Contributor

eahlberg commented Oct 7, 2022

When I upgraded yesod-test to version 1.6.15 I noticed some tests started to fail, e.g.:

htmlAnyContain "meta[name=description]" "content=\"This is the site description\""

Fails with:

None of meta[name=description] contain content="This is the site description matches: ["<meta content=\"This is the site description\" name=\"description\" />"]

AFAIU this is because htmlAnyContain was changed to support matching e.g. quotes (') by escaping input by default.

I guess it's not possible to support both of these cases with the same API? To work around this locally I have the old version of htmlAnyContain around which does not escape input. If that's sounds like a sensible solution, I could open a PR which brings back that version under a new name (e.g. htmlAnyContainPreEscaped) to avoid other people (and my future self) running into this issue.

@eahlberg eahlberg changed the title [yesod-test] bring back support for matching of preescaped strings [yesod-test] bring back support for matching of preescaped strings Oct 7, 2022
@schoettl
Copy link
Contributor

schoettl commented Oct 7, 2022

I think it's a very valid use case to check if some raw HTML is contained verbatim. So I would appreciate an additional API like htmlAnyContainedPreEscaped. Maybe put the keywords "verbatim" or "raw" in the documentation to make it easier to find it...

@jezen
Copy link
Member

jezen commented Oct 7, 2022

A pull request with that function sounds sensible. Let's do it.

@jezen
Copy link
Member

jezen commented Oct 10, 2022

In case it's useful, until that function exists, this stopgap should work:

htmlQuery "meta[name=description]" >>= \(bs:_) ->
  liftIO $ bs `shouldSatisfy` ("This is the site description" `isInfixOf`)

@eahlberg
Copy link
Contributor Author

@jezen cool, thanks! I opened a PR which adds the discussed function (htmlAnyContainPreEscaped) as well as the accompanying functions htmlAllContainPreEscaped and htmlNoneContainPreEscaped in #1786

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