You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2012/11/02 17:42:51 UTC

[2/2] git commit: Don't trust that String.trim() exists

Don't trust that String.trim() exists


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/8043663e
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/8043663e
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/8043663e

Branch: refs/heads/5.4-js-rewrite
Commit: 8043663e14e7957e28c4dcbc0679f83b7f9ebf29
Parents: ac7f263
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Fri Nov 2 09:40:56 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Fri Nov 2 09:40:56 2012 -0700

----------------------------------------------------------------------
 .../META-INF/modules/core/builder.coffee           |    4 ++--
 .../META-INF/modules/core/utils.coffee             |   11 ++++++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8043663e/tapestry-core/src/main/coffeescript/META-INF/modules/core/builder.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/builder.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/builder.coffee
index 8f5e1bf..0b247d3 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/builder.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/builder.coffee
@@ -45,12 +45,12 @@
 # and
 #
 #     { on: { click: -> ... }}
-define ["_", "core/spi"], (_, spi) ->
+define ["_", "core/spi", "core/utils"], (_, spi, utils) ->
   # _internal_: creates a single DOM element and CSS class attribute
   createElement = (elementDescription) ->
     # TODO: Support #id for setting the id of an element, maybe others, such as ?name for the name of an input element.
     # That will require a regex or more sophisticated parsing.
-    terms = elementDescription.trim().split(".")
+    terms = utils.trim(elementDescription).split(".")
 
     elementName = terms.shift() or "div"
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8043663e/tapestry-core/src/main/coffeescript/META-INF/modules/core/utils.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/utils.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/utils.coffee
index d4e9905..dd8e173 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/utils.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/utils.coffee
@@ -17,4 +17,13 @@
 # A few handy functions.
 define [], ->
 
-  isBlank: (input) -> input is null or input.trim().length == 0
\ No newline at end of file
+  trim = (input) ->
+    if String.prototype.trim
+      input.trim()
+    else
+      input.replace(/^\s+/, '').replace(/\s+$/, '')
+
+  exports =
+    # Trims leading and trailing whitespace from a string. Delegates to String.prototype.trim if present.
+    trim: trim
+    isBlank: (input) -> input is null or (exports.trim input).length == 0
\ No newline at end of file