[Pkg-javascript-commits] [dojo] 35/149: don't match leading/trailing spaces when there is no currency symbol. fixes #18466

David Prévot taffit at moszumanska.debian.org
Sat Feb 27 03:13:45 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository dojo.

commit f0d04b79749cd292fc30fcd11e4fd1ed51f6633e
Author: Clément Mathieu <clement.mathieu at outlook.com>
Date:   Mon Feb 9 15:34:42 2015 +0100

    don't match leading/trailing spaces when there is no currency symbol. fixes #18466
---
 number.js | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/number.js b/number.js
index a6c73d5..78f3187 100644
--- a/number.js
+++ b/number.js
@@ -86,9 +86,14 @@ number._applyPattern = function(/*Number*/ value, /*String*/ pattern, /*number._
 	}else if(pattern.indexOf('\u00a4') != -1){
 		group = options.customs.currencyGroup || group;//mixins instead?
 		decimal = options.customs.currencyDecimal || decimal;// Should these be mixins instead?
-		pattern = pattern.replace(/\u00a4{1,3}/, function(match){
-			var prop = ["symbol", "currency", "displayName"][match.length-1];
-			return options[prop] || options.currency || "";
+		pattern = pattern.replace(/([\s\xa0]*)(\u00a4{1,3})([\s\xa0]*)/, function(match, before, target, after){
+			var prop = ["symbol", "currency", "displayName"][target.length-1],
+				symbol = options[prop] || options.currency || "";
+			// if there is no symbol, also remove surrounding whitespaces
+			if(!symbol){
+				return "";
+			}
+			return before+symbol+after;
 		});
 	}else if(pattern.indexOf('E') != -1){
 		throw new Error("exponential notation not supported");
@@ -350,6 +355,12 @@ number._parseInfo = function(/*Object?*/ options){
 		re = re.replace(/([\s\xa0]*)(\u00a4{1,3})([\s\xa0]*)/g, function(match, before, target, after){
 			var prop = ["symbol", "currency", "displayName"][target.length-1],
 				symbol = dregexp.escapeString(options[prop] || options.currency || "");
+
+			// if there is no symbol there is no need to take white-spaces into account.
+			if(!symbol){
+				return "";
+			}
+
 			before = before ? "[\\s\\xa0]" : "";
 			after = after ? "[\\s\\xa0]" : "";
 			if(!options.strict){

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list