Opened 12 years ago

Closed 12 years ago

#2679 closed defect (wontfix)

dojo.string.encodeAscii regular expression

Reported by: Michael Schall Owned by: Adam Peller
Priority: high Milestone:
Component: String Version: 0.4.2
Keywords: Cc:
Blocked By: Blocking:

Description

The comment above dojo.string.encodeAscii says it all... This is an important function as it is used in dojo.io.bind to encode all strings sent up to the server unless you are using utf.

I don't know what the regular expression is testing for. It looks like it would never find a match anyway... The escape on the string before the test would switch any % to %25 so the check for a '%u' is useless.

If I'm not reading the regular expression correctly, sorry.

//FIXME: not sure exactly what encodeAscii is trying to do, or if it's working right
dojo.string.encodeAscii = function(/*string*/str){
	if(!dojo.lang.isString(str)){ return str; } // unknown
	var ret = "";
	var value = escape(str);
	var match, re = /%u([0-9A-F]{4})/i;
	while((match = value.match(re))){
		var num = Number("0x"+match[1]);
		var newVal = escape("&#" + num + ";");
		ret += value.substring(0, match.index) + newVal;
		value = value.substring(match.index+match[0].length);
	}
	ret += value.replace(/+/g, "%2B");
	return ret; // string
}

If this test is needed, it should be moved above the escape.

If a match can be made, the replace of the + character should be on the whole string, not just what is left after regular expression matching is complete.

	ret += value.replace(/+/g, "%2B");

Should be

	ret += value; //add remainder of string after matches
	ret = ret.replace(/+/g, "%2B"); //replace + in entire string

Change History (2)

comment:1 Changed 12 years ago by Adam Peller

Owner: changed from psowden to Adam Peller

comment:2 Changed 12 years ago by Adam Peller

Resolution: wontfix
Status: newclosed

This method no longer exists in 0.9

Note: See TracTickets for help on using tickets.