# HG changeset patch # User hamidouk # Date 1322736035 -3600 # Node ID 70bc85b31c6deaafc1193ccf9aa7fcedd19d7e93 # Parent 0d7326fe77e7e2ad643bad9a495877d81fd9b0d3 added a function to strictly encode uri components. diff -r 0d7326fe77e7 -r 70bc85b31c6d src/js/utils.js --- a/src/js/utils.js Wed Nov 30 17:27:12 2011 +0100 +++ b/src/js/utils.js Thu Dec 01 11:40:35 2011 +0100 @@ -103,6 +103,15 @@ return Mustache.to_html(template, params); }; +/* we need to be stricter than encodeURIComponent, + because of twitter +*/ +IriSP.encodeURI = function(str) { + return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28'). + replace(/\)/g, '%29').replace(/\*/g, '%2A'); +} + + /* for ie compatibility if (Object.prototype.__defineGetter__&&!Object.defineProperty) { Object.defineProperty=function(obj,prop,desc) { diff -r 0d7326fe77e7 -r 70bc85b31c6d unittests/tests/utils.js --- a/unittests/tests/utils.js Wed Nov 30 17:27:12 2011 +0100 +++ b/unittests/tests/utils.js Thu Dec 01 11:40:35 2011 +0100 @@ -57,4 +57,8 @@ IriSP.default_templates_vars["test_fixture"] = "FIXTURE"; equal(IriSP.templToHTML("{{test_fixture}} {{foo}}", {foo: 2}), "FIXTURE 2", "correct template returned"); }); + + test("test url encoding function", function() { + equal(IriSP.encodeURI("!'()*"), "%21%27%28%29%2A", "the returned string is correct"); + }); }