Permalink
Browse files

normalizing line endings and trimming trailing whitespace in post mat…

…ching
  • Loading branch information...
1 parent 62bb873 commit 3446cddcb134c490ddcac992a4cd8eb72f17d99a @mrak committed Feb 28, 2013
Showing with 11 additions and 4 deletions.
  1. +4 −0 CHANGELOG.md
  2. +1 −1 package.json
  3. +6 −3 src/models/endpoint.coffee
View
@@ -1,5 +1,9 @@
# Changelog
+## 0.1.44
+
+* line endings are normalized to `\n` and trailing whitespace is trimmed from the end when matching request's post/file contents
+
## 0.1.43
* `response.file` and `request.file` are now relative paths from the root data.yaml instead of being relative from the source of execution
View
@@ -1,7 +1,7 @@
{
"name": "stubby",
"preferGlobal": true,
- "version": "0.1.43",
+ "version": "0.1.44",
"author": {
"name": "Eric Mrak",
"email": "enmrak@gmail.com"
@@ -1,6 +1,9 @@
fs = require 'fs'
path = require 'path'
+normalizeEOL = (string) ->
+ return (string.replace /\r\n/g, '\n').replace /\s*$/, ''
+
purifyHeaders = ->
for prop, value of @request.headers
delete @request.headers[prop]
@@ -31,7 +34,7 @@ pruneUndefined = ->
setFallbacks = (endpoint) ->
if endpoint.request.file?
- try endpoint.request.post = (fs.readFileSync endpoint.request.file, 'utf8').trim()
+ try endpoint.request.post = fs.readFileSync endpoint.request.file, 'utf8'
if endpoint.response.file?
try endpoint.response.body = fs.readFileSync endpoint.response.file, 'utf8'
@@ -74,10 +77,10 @@ module.exports = class Endpoint
file = null
if @request.file?
- try file = (fs.readFileSync path.resolve(@datadir, @request.file), 'utf8').trim()
+ try file = fs.readFileSync path.resolve(@datadir, @request.file), 'utf8'
if post = file or @request.post
- return false unless post is request.post
+ return false unless normalizeEOL(post) is normalizeEOL(request.post)
if @request.method instanceof Array
return false unless request.method in @request.method.map (it) -> it.toUpperCase()

0 comments on commit 3446cdd

Please sign in to comment.