Orange-OpenSource / hurl

Hurl, run and test HTTP requests with plain text.
https://hurl.dev
Apache License 2.0
12.98k stars 486 forks source link

Accept alternative quotes for response predicate test #3317

Open infogulch opened 3 days ago

infogulch commented 3 days ago

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

jcamiel commented 3 days ago

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 commented 3 days ago

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.

jcamiel commented 3 days ago

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