[CRX] Avoid encoding the fragment in file key
Semantically, it is more correct to encode the fragment in the URL instead of the URL-encoded `file` query parameter. This shouldn't matter in practice, because `rewriteUrlClosure` in `chromecom.js` decodes the `file` parameter and restores the fragment. However, as #16625 shows, there was a case where this did not work as expected.
This commit is contained in:
parent
1d07ef401e
commit
f2753d6220
@ -20,7 +20,15 @@ limitations under the License.
|
|||||||
var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html");
|
var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html");
|
||||||
|
|
||||||
function getViewerURL(pdf_url) {
|
function getViewerURL(pdf_url) {
|
||||||
return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url);
|
// |pdf_url| may contain a fragment such as "#page=2". That should be passed
|
||||||
|
// as a fragment to the viewer, not encoded in pdf_url.
|
||||||
|
var hash = "";
|
||||||
|
var i = pdf_url.indexOf("#");
|
||||||
|
if (i > 0) {
|
||||||
|
hash = pdf_url.slice(i);
|
||||||
|
pdf_url = pdf_url.slice(0, i);
|
||||||
|
}
|
||||||
|
return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url) + hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user