From e6a53420f64fbf4097a014a80006a8590ed6db6c Mon Sep 17 00:00:00 2001 From: MegaDiablo Date: Tue, 9 Jun 2015 09:23:06 +0300 Subject: [PATCH] Add support of unicode characters for X-PJAX-URL Add support of unicode characters for X-PJAX-URL parameter. It's increase level of support internalisation --- jquery.pjax.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/jquery.pjax.js b/jquery.pjax.js index f1728d45..2e27a1ec 100644 --- a/jquery.pjax.js +++ b/jquery.pjax.js @@ -594,6 +594,18 @@ function stripHash(location) { return location.href.replace(/#.*/, '') } +// Internal: Parse unicode character and return unescaped String. Unicode +// character looks like "\u0000". +// +// url - String URL +// +// Return String +function unescapeUnicode(url){ + return url.replace(/\\u([\d\w]{4})/gi, function (match, grp) { + return String.fromCharCode(parseInt(grp, 16)); + }); +} + // Internal: Build options Object for arguments. // // For convenience the first parameter can be either the container or @@ -687,7 +699,7 @@ function extractContainer(data, xhr, options) { // Prefer X-PJAX-URL header if it was set, otherwise fallback to // using the original requested url. var serverUrl = xhr.getResponseHeader('X-PJAX-URL') - obj.url = serverUrl ? stripInternalParams(parseURL(serverUrl)) : options.requestUrl + obj.url = serverUrl ? stripInternalParams(parseURL(unescapeUnicode(serverUrl))) : options.requestUrl // Attempt to parse response html into elements if (fullDocument) {