Giter VIP home page Giter VIP logo

Comments (7)

speekha avatar speekha commented on June 8, 2024 1

That's the way I understand it too: basically, switching the regex to "literal" is like replacing it with a simple String.equals, which is not ideal because it's quite useful to be able to only look for patterns instead of an exact match.
I think I need to look at regex syntax again to find a way to write that body request in a way that won't be mistaken as an incorrect regex syntax. Will keep you posted.

from httpmocker.

speekha avatar speekha commented on June 8, 2024 1

@nnobelis Correction has been published in 1.3. Let me know if you have any further requests.

from httpmocker.

speekha avatar speekha commented on June 8, 2024

Thanks for the feedback. You're right that recorded scenarios should work with as little clean up as possible (although a minimum is probably always needed because ALL request parameters will be recorded, including some that might be dynamic or constantly changing like authentication tokens for a connected API for instance). As for your suggestion about using RegexOption.LITERAL, could you help me what difference it would make? The doc is minimal on this field, and I'm not sure if it means that the expression will not be considered as an actual regex anymore but more like an exact string to match?
I'm going to look into it as quickly as possible.

from httpmocker.

nnobelis avatar nnobelis commented on June 8, 2024

Thanks a lot for the quick response.
As I understand, with RegexOption.LITERAL, the special characters in the string with be ignored and the full string will be used for an exact match : if you have .* in your string, these two characters will be matched.
The problem is that if you always use RegexOption.LITERAL, pattern matching in the body won't be possible any more.

I think the solution is in something like this : if you use RECORD, you get a body like before and it will be matched with RegexOption.LITERAL exactly.
But you can also specify bodyPattern which is indeed a pattern with normal RegEx matching. This bodyPattern takes precedence over body.
Something like that :

 "request" : {
    "method" : "POST",
    "headers" : { },
    "params" : { },
    "body" : "{\"data\":{\"username\":\"XXX\",\"key\":\"XXX\",\"project_code\":\"Explorers_Helidon\"},\"action\":\"get_information\",\"group\":\"projects\"}",
    "bodyPattern": ".*get_information.*"
  },

But this is a breaking change for your users so you may want to do it "backwards" with bodyRaw for instance and body :)

    "bodyRaw" : "{\"data\":{\"username\":\"XXX\",\"key\":\"XXX\",\"project_code\":\"Explorers_Helidon\"},\"action\":\"get_information\",\"group\":\"projects\"}",
    "body": ".*get_information.*"

from httpmocker.

sschuberth avatar sschuberth commented on June 8, 2024

Can't you just use Regex.escapeReplacement() when serializing the body to the recorded JSON file, so that any literal characters that have a special meaning in regex are escaped? Then it should work out of the box. However, I'd also rename the body field to bodyRegex in the same run to make the expected syntax explicit.

from httpmocker.

speekha avatar speekha commented on June 8, 2024

That's a good option. That's the kind of solution I'm planning to look into.

from httpmocker.

speekha avatar speekha commented on June 8, 2024

@nnobelis I've pushed a correction for your issue. I preferred keeping the current API. So request body is converted to a for an exact match regexp. Feel free to test it from develop if you want and make comments before I publish a new version.

from httpmocker.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.