Skip to content
This repository was archived by the owner on Aug 3, 2022. It is now read-only.

Commit b5983cc

Browse files
committed
Fix absolute path in srcset.
1 parent a440541 commit b5983cc

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

background.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ function TestRemoteBlob(url, port, tab_url) {
105105
fetch_url = "https:" + url;
106106
}
107107
if (!fetch_url.startsWith("http")) {
108-
fetch_url = tab_url + "/" + fetch_url;
108+
if (fetch_url.startsWith("/")) {
109+
// If an absolute path, it is relative to the domain.
110+
fetch_url = (new URL(tab_url)).origin + "/" + fetch_url;
111+
} else {
112+
// Otherwise, it is relative to the current URL.
113+
fetch_url = tab_url + "/" + fetch_url;
114+
}
109115
}
110116
var fetch_headers = new Headers();
111117
fetch_headers.append("Accept", "image/webp,image/*,*/*;q=0.8");
@@ -162,6 +168,8 @@ function TestRemoteBlob(url, port, tab_url) {
162168
*/
163169
function TestUrl(url, port) {
164170
if (url == undefined) return;
171+
url = url.trim();
172+
if (url == "") return;
165173
if (url.includes("base64")) {
166174
if (url.includes("image/webp")) {
167175
// Base64 like on Amazon.

webp_reformatter.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,14 @@ var TestForWebp = function() {
207207
if (has_space) {
208208
src = srcset.substring(start, end);
209209
} else {
210-
// If no space was found before, we need to have a space after
211-
// the comma introducing the next string.
212-
if (!/\s/g.test(srcset[i + 1])) continue;
213-
src = srcset.substring(start, i);
210+
if (i == srcset.length - 1) {
211+
src = srcset.substring(start);
212+
} else {
213+
// If no space was found before, we need to have a space after
214+
// the comma introducing the next string.
215+
if (!/\s/g.test(srcset[i + 1])) continue;
216+
src = srcset.substring(start, i);
217+
}
214218
}
215219
TestUrl(src, img);
216220
// Get to the next non-white space.

0 commit comments

Comments
 (0)