comparison lib/js/urweb.js @ 1087:e81434513720

Proper JavaScript-side URI escaping/de-escaping; fix C-side URL encoding of big characters
author Adam Chlipala <adamc@hcoop.net>
date Thu, 24 Dec 2009 10:44:53 -0500
parents e8a35d710ab9
children 6e5463a53c3c
comparison
equal deleted inserted replaced
1086:99aebdf30257 1087:e81434513720
581 } 581 }
582 582
583 function uf(s) { 583 function uf(s) {
584 if (s.length == 0) 584 if (s.length == 0)
585 return "_"; 585 return "_";
586 return (s.charAt(0) == '_' ? "_" : "") 586 return (s.charAt(0) == '_' ? "_" : "") + encodeURIComponent(s);
587 + escape(s).replace(new RegExp ("/", "g"), "%2F").replace(new RegExp ("\\+", "g"), "%2B");
588 } 587 }
589 588
590 function uu(s) { 589 function uu(s) {
591 if (s.length > 0 && s.charAt(0) == '_') { 590 if (s.length > 0 && s.charAt(0) == '_') {
592 s = s.substring(1); 591 s = s.substring(1);
593 } else if (s.length >= 3 && s.charAt(0) == '%' && s.charAt(1) == '5' && (s.charAt(2) == 'f' || s.charAt(2) == 'F')) 592 } else if (s.length >= 3 && s.charAt(0) == '%' && s.charAt(1) == '5' && (s.charAt(2) == 'f' || s.charAt(2) == 'F'))
594 s = s.substring(3); 593 s = s.substring(3);
595 return unescape(s.replace(new RegExp ("\\+", "g"), " ")); 594 return decodeURIComponent(s.replace(new RegExp ("\\+", "g"), " "));
596 } 595 }
597 596
598 function ub(b) { 597 function ub(b) {
599 return b ? "1" : "0"; 598 return b ? "1" : "0";
600 } 599 }