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

Accept alternative quotes for response predicate test #3317

Closed
1 task
infogulch opened this issue Oct 19, 2024 · 5 comments · Fixed by #3332
Closed
1 task

Accept alternative quotes for response predicate test #3317

infogulch opened this issue Oct 19, 2024 · 5 comments · Fixed by #3332
Labels
enhancement New feature or request
Milestone

Comments

@infogulch
Copy link
Contributor

Problem to solve

Sometimes when asserting a response I want to match body or query contents that themselves contain quotes so they must be escaped. This is annoying to do, but also makes it hard to read.

Proposal

It would be nice if hurl could parse strings with alternate quotes so other quote types would not need to be escaped.

Additional context and resources

Example output of what happens if you try to use single quotes in the way I described above today:

error: Parsing predicate value
  --> /home/joe/xtemplate/test/tests/nats.hurl:11:15
   |
11 | body contains 'data: "<li>hello 1</li>"\n\n'
   |               ^ invalid predicate value

Tasks to complete

  • Parse predicate strings with single quotes
@infogulch infogulch added the enhancement New feature or request label Oct 19, 2024
@jcamiel
Copy link
Collaborator

jcamiel commented Oct 19, 2024

Hi @infogulch

I think cou can use one line string and multi line string even if they're not body

https://hurl.dev/docs/request.html#oneline-string-body

POST https://example.org/helloworld
`Hello world!`

You can try, it may works in predicate

@infogulch
Copy link
Contributor Author

infogulch commented Oct 20, 2024

Unfortunately it doesn't work:

error: Parsing predicate value
  --> /home/joe/xtemplate/test/tests/nats.hurl:11:15
   |
11 | body contains `data: "<li>hello 1</li>"\n\n`
   |               ^ invalid predicate value
   |

Other variations I tried:

body contains `data: "<li>hello 1</li>"`               i.e. no trailing \n\n

body contains ```data: "<li>hello 1</li>"```

body contains ```
data: "<li>hello 1</li>"
```

I think backticks would be fine to use instead of single quotes if you want to keep the syntax consistent. Multiline would be nice as well.

@infogulch infogulch changed the title Accept Accept alternative quotes for response predicate test Oct 20, 2024
@jcamiel
Copy link
Collaborator

jcamiel commented Oct 20, 2024

Thanks @infogulch I was pretty sure this could work. I think we'll implement support for single and triple backticks.

@jcamiel jcamiel added this to the 6.0.0 milestone Oct 24, 2024
@jcamiel jcamiel linked a pull request Oct 24, 2024 that will close this issue
@jcamiel
Copy link
Collaborator

jcamiel commented Oct 24, 2024

Hi @infogulch on master you can use single backtick string like this:

GET http://foo.com
HTTP 200
[Asserts]
xpath "string(//title)" == `Bob says: "Hi"`

Regards,

@infogulch
Copy link
Contributor Author

Awesome, thanks! I will report back after I try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants