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

Fix line breaks ruining call tag regexp #109

Merged
merged 1 commit into from
May 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/html/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ <h1>Miscellaneous utility functions.</h1>
<h2>string strip (string)</h2>
<p>Strip extra whitespace from both ends of the string, and remove
line breaks anywhere in the string.</p>
<h2>string trim (string)</h2>
<p>Compatible implementation of <code>String.prototype.trim()</code>. Strips whitespace
from the beginning and end of the string, but doesn't remove any
whitespace inside the string like <code>strip()</code> does.</p>
<h2>void extend (object a, object b)</h2>
<p>Combine the properties of both objects into one. The properties from
object 'b' are inserted into 'a'.</p>
Expand Down
6 changes: 6 additions & 0 deletions docs/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
Strip extra whitespace from both ends of the string, and remove
line breaks anywhere in the string.

## string trim (string)

Compatible implementation of `String.prototype.trim()`. Strips whitespace
from the beginning and end of the string, but doesn't remove any
whitespace inside the string like `strip()` does.

## void extend (object a, object b)

Combine the properties of both objects into one. The properties from
Expand Down
4 changes: 2 additions & 2 deletions src/brain.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Brain
processCallTags: (reply, scope, async) ->
reply = reply.replace(/\{__call__\}/g, "<call>")
reply = reply.replace(/\{\/__call__\}/g, "</call>")
callRe = /<call>(.+?)<\/call>/ig
callRe = /<call>([\s\S]+?)<\/call>/ig
argsRe = /{__call_arg__}([^{]*){\/__call_arg__}/ig

giveup = 0
Expand All @@ -109,7 +109,7 @@ class Brain
if not match
break

text = utils.strip(match[1])
text = utils.trim(match[1])

# get subroutine name
subroutineNameMatch = (/(\S+)/ig).exec(text)
Expand Down
20 changes: 16 additions & 4 deletions src/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@
exports.strip = (text) ->
text = text.replace(/^[\s\t]+/, "") \
.replace(/[\s\t]+$/, "") \
.replace(/[\x0D\x0A]+/, "");
.replace(/[\x0D\x0A]+/, "")
return text

##
# string trim (string)
#
# Compatible implementation of `String.prototype.trim()`. Strips whitespace
# from the beginning and end of the string, but doesn't remove any
# whitespace inside the string like `strip()` does.
##
exports.trim = (text) ->
text = text.replace(/^[\x0D\x0A\s\t]+/, "") \
.replace(/[\x0D\x0A\s\t]+$/, "")
return text

##
Expand Down Expand Up @@ -138,7 +150,7 @@ exports.clone = (obj) ->
# Determines if obj looks like a promise
##
exports.isAPromise = (obj) ->
return obj and obj.then and obj.catch and obj.finally and
typeof obj.then is 'function' and
return obj and obj.then and obj.catch and obj.finally and
typeof obj.then is 'function' and
typeof obj.catch is 'function' and
typeof obj.finally is 'function'
typeof obj.finally is 'function'