Skip to content

Helper methods for using URI.js against servers not understanding UTF-8 encoded URIs #10

Merged
merged 1 commit into from Jan 12, 2012
View
18 docs.html
@@ -116,6 +116,8 @@
<li><a href="#static-commonPath">URI.commonPath()</a></li>
<li><a href="#static-withinString">URI.withinString()</a></li>
+ <li><a href="#static-iso8859">URI.iso8859()</a></li>
+ <li><a href="#static-unicode">URI.unicode()</a></li>
</ul>
</li>
</ul>
@@ -757,6 +759,20 @@ <h3 id="static-withinString">URI.withinString()</h3>
});
</pre>
+ <h3 id="static-iso8859">URI.iso8859()</h3>
+ <p>URI.iso8859() tells URI.js to use the older escape/unescape methods, for backwards compatibility with older platforms.</p>
+ <pre class="prettyprint lang-js">URI.iso8859();
+
+var uri = new URI("http://example.org/foo/æ.html");
+// http://example.org/foo/%E6.html</pre>
+
+ <h3 id="static-unicode">URI.unicode()</h3>
+ <p>URI.unicode() restores the default unicode-encoded URLs.</p>
+ <pre class="prettyprint lang-js">URI.unicode();
+
+var uri = new URI("http://example.org/foo/æ.html");
+// http://example.org/foo/%C3%A6.html</pre>
+
</div>
</body>
-</html>
+</html>
View
20 src/URI.js
@@ -65,8 +65,18 @@ var URI = function(url, base) {
}
return this;
- },
- p = URI.prototype;
+ };
+var p = URI.prototype;
+
+URI.iso8859 = function() {
+ URI.encode = escape;
+ URI.decode = unescape;
+}
+
+URI.unicode = function() {
+ URI.encode = encodeURIComponent;
+ URI.decode = decodeURIComponent;
+}
// static properties
URI.idn_expression = /[^a-z0-9\.-]/i;
@@ -122,10 +132,10 @@ URI.characters = {
}
};
URI.encodeQuery = function(string) {
- return encodeURIComponent(string + "").replace(/%20/g, '+');
+ return URI.encode(string + "").replace(/%20/g, '+');
};
URI.decodeQuery = function(string) {
- return decodeURIComponent((string + "").replace(/\+/g, '%20'));
+ return URI.decode((string + "").replace(/\+/g, '%20'));
};
URI.recodePath = function(string) {
var segments = (string + "").split('/');
@@ -1260,4 +1270,4 @@ p.equals = function(uri) {
window.URI = URI;
-})();
+})();
Something went wrong with that request. Please try again.