Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of unicode characters for X-PJAX-URL #535

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion jquery.pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down