[Laszlo-dev] UPDATED For Review: Change 20090105-hqm-R Summary: fix url encoding problem
André Bargull
andre.bargull at udo.edu
Tue Jan 6 09:07:13 PST 2009
On 1/6/2009 5:49 PM, Henry Minsky wrote:
> I like having a single common url escape routine across all runtimes,
> it makes debugging simpler.
Even if it is _much_ slower? The following testcase (in swf8) was about
50 times slower when "escape_utf8" was used instead of "escape"...
---
<canvas bgcolor="0x898989" debug="true">
<button text="escape" >
<handler name="onclick" ><![CDATA[
var d = new Date();
for (var i=0; i<4000; ++i)escape("encode me éêè");
Debug.write(new Date()-d)
]]></handler>
</button>
<button x="100" text="escape_utf8" >
<handler name="onclick" ><![CDATA[
function escape_utf8 (s) {
var utf8 = "";
for (var i = 0, len = s.length; i < len; ++i) {
var c = s.charCodeAt(i);
if ((c >= 0x30 && c <= 0x39) // 0-9
|| (c >= 0x41 && c <= 0x5A) // A-Z
|| (c >= 0x61 && c <= 0x7A)) {// a-z
utf8 += s.charAt(i);
} else if (c <= 0x7F) {
// 0xxxxxxx
utf8 += "%" + (c).toString(16).toUpperCase();
} else if (c <= 0x7FF) {
// 110xxxxx 10xxxxxx
utf8 += "%" + ((c >> 6) | 0xC0).toString(16).toUpperCase();
utf8 += "%" + ((c & 0x3F) | 0x80).toString(16).toUpperCase();
} else if (c <= 0xFFFF) {
// 1110xxxx 10xxxxxx 10xxxxxx
utf8 += "%" + ((c >> 12) | 0xE0).toString(16).toUpperCase();
utf8 += "%" + (((c >> 6) & 0x3F) |
0x80).toString(16).toUpperCase();
utf8 += "%" + ((c & 0x3F) | 0x80).toString(16).toUpperCase();
} else {
// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
utf8 += "%" + ((c >> 18) | 0xF0).toString(16).toUpperCase();
utf8 += "%" + (((c >> 12) & 0x3F) |
0x80).toString(16).toUpperCase();
utf8 += "%" + (((c >> 6) & 0x3F) |
0x80).toString(16).toUpperCase();
utf8 += "%" + ((c & 0x3F) | 0x80).toString(16).toUpperCase();
}
}
return utf8;
}
var d = new Date();
for (var i=0; i<4000; ++i)escape_utf8("encode me éêè")
Debug.write(new Date()-d)
]]></handler>
</button>
</canvas>
---
>
> I just modified your utf8 escape routine to pad the extra zero when needed
>
>
> var escape_utf8 = function (s:String):String {
> var utf8 = "";
> for (var i = 0, len = s.length; i < len; ++i) {
> var c = s.charCodeAt(i);
> if ((c >= 0x30 && c <= 0x39) // 0-9
> || (c >= 0x41 && c <= 0x5A) // A-Z
> || (c >= 0x61 && c <= 0x7A)) {// a-z
> utf8 += s.charAt(i);
> } else if (c < 0x10) {
> // 0xxxxxxx
> utf8 += "%0" + (c).toString(16).toUpperCase();
> } else if (c <= 0x7F) {
> // 0xxxxxxx
> utf8 += "%" + (c).toString(16).toUpperCase();
> ...
> ...
>
>
>
>
> On Tue, Jan 6, 2009 at 11:49 AM, André Bargull <andre.bargull at udo.edu> wrote:
>> As an alternative, we could (maybe should?) use:
>> - in swf8: escape
>> - in dhtml+swf9: encodeURIComponent [1] with a few modifications so it also
>> encodes "- _ . ! ~ * ' ( )" into the appropriate UTF-8 encoding
>>
>> [1]
>> "https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/encodeURIComponent"
>>
>>
>>
>> On 1/6/2009 5:29 PM, Henry Minsky wrote:
>>> Hang on, there's a bug in the escape_utf8 routine, it's encoding
>>> newline as "%A" instead of "%0A", I need
>>> to fix that.
>>>
>>>
>>>
>>>
>>>
>>> On Tue, Jan 6, 2009 at 2:19 AM, Henry Minsky <henry.minsky at gmail.com>
>>> wrote:
>>>> Change 20090105-hqm-R by hqm at badtzmaru.home on 2009-01-05 19:40:54 EST
>>>> in /Users/hqm/openlaszlo/trunk3/WEB-INF/lps/lfc
>>>> for http://svn.openlaszlo.org/openlaszlo/trunk/WEB-INF/lps/lfc
>>>>
>>>> Summary: fix url encoding problem
>>>>
>>>> New Features:
>>>>
>>>> Bugs Fixed: LPP-7532
>>>>
>>>> Technical Reviewer: andre
>>>> QA Reviewer: ptw
>>>> Doc Reviewer: (pending)
>>>>
>>>> Documentation:
>>>>
>>>> Release Notes:
>>>>
>>>> The recommended way to url-escape strings is to call
>>>> lz.Browser.urlEscape.
>>>> This works similar to the Javascript encodeURIComponent function, but is
>>>> preferable
>>>> because there are some knows bugs with encodeURIComponent on some
>>>> platforms.
>>>>
>>>> Details:
>>>>
>>>> Use Andre's utf-8 clean implementation of encodeURIComponent.
>>>>
>>>> Tests:
>>>>
>>>> demos/amazon/amazon.lzx in swf8,swf9,dhtml
>>>> test/lfc/data/alldata.lzx (alldata.lzx has bugs, but there should be no
>>>> regressions from behavior in trunk)
>>>> demos/lzpix/app.lzx in swf8,swf9,dhtml
>>>> demos/calendar/calendar.lzx in swf8,swf9,dhtml
>>>>
>>>> Files:
>>>> M kernel/swf/LzLoadQueue.as
>>>> M services/LzBrowser.lzs
>>>> M debugger/platform/swf9/LzFlashRemote.as
>>>> M data/LzParam.lzs
>>>> M compiler/LzRuntime.lzs
>>>> M compiler/LzBootstrapDebugService.lzs
>>>>
>>>> Changeset:
>>>> http://svn.openlaszlo.org/openlaszlo/patches/20090105-hqm-R.tar
>>>>
>>>
>>>
>>
>
>
>
More information about the Laszlo-dev
mailing list