gstroup / apimocker

node.js module to run a simple http server for mock service responses.
MIT License
280 stars 81 forks source link

- added support of special characters in switch argument, fixed small typo in switched file naming #6

Closed igutsaliuk closed 10 years ago

igutsaliuk commented 10 years ago

This fix corrent issue when you have special characters in your switch value that could not be repesented as a file. ([swith][value].[mockFile])

"webServers" : {
   "some/url" : {
      "mockFile" : "file.json",
      "verbs" : ["get"],
      "switch": "path"
   }
}

with following URI:

http://somehost/some/url?path=/

will now try to search for "path2%F.file.json" instead of "path/.file.json"

gstroup commented 10 years ago

Hi @quonlee, thanks for the pull request. And thanks for fixing that typo in the read me file. Can you explain your use case a little bit?? I'm not sure why you would want to pass in a slash as part of your switch value. Nested paths can already be passed in to the "mockFile" setting for a web service.

igutsaliuk commented 10 years ago

Sorry for confusing, I'll try to explain with better example:

You got API query such as: mysite.com/app/browser?path="../foo/bar/file.zip" with switcher "path" and mockFIle "browser.json". ApiMocker would try to search for following mock file : "path../foo/bar/file.zip.browser.json" but such file can't exist, since FS doesn't suppport special characters in file name. The logical solution is to encode into "path..%2Ffoo%2Fbar%2Ffile.zip.browser.json" Looks kinda ugly but at least works fine :)

Otherwise please advice a better solution to resolve this issue.

Thanks for a great tool, Igor

gstroup commented 10 years ago

@quonlee - I changed one line of your code, so we don't break nested paths in the "mockFile" setting. Just published it to npm. Thanks!