aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2020-12-29 14:16:25 -0800
committerOmar Rizwan <omar@omar.website>2020-12-29 14:16:25 -0800
commit1185e6885c1dc935592ad14cb0955a9d57dc20e7 (patch)
treebdc1be74c35c0a16d7aac8ca3e733d8f4527c1a4
parent6c56c525f22ae97977c466c25e3726a23fa04887 (diff)
ability to read scripts/file with path filtering
-rw-r--r--extension/background.js18
-rw-r--r--test/test.c1
2 files changed, 11 insertions, 8 deletions
diff --git a/extension/background.js b/extension/background.js
index 5cb3a8c..51a2bbd 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -296,16 +296,21 @@ router["/tabs/by-id/*/control"] = {
return { entries: [".", "..", ...scriptFileNames] };
}
};
+ function pathScriptInfo(tabId, path) {
+ const [scriptId, ...rest] = pathComponent(path, -1).split("_");
+ const scriptInfo = TabManager.scriptsForTab[tabId][scriptId];
+ if (!scriptInfo || sanitize(scriptInfo.url).slice(0, 200) !== rest.join("_")) {
+ throw new UnixError(unix.ENOENT);
+ }
+ return scriptInfo;
+ }
router["/tabs/by-id/*/debugger/scripts/*"] = defineFile(async path => {
const [tabId, suffix] = [parseInt(pathComponent(path, -4)), pathComponent(path, -1)];
await TabManager.debugTab(tabId);
await TabManager.enableDomainForTab(tabId, "Page");
await TabManager.enableDomainForTab(tabId, "Debugger");
- const parts = pathComponent(path, -1).split("_"); const scriptId = parts[0];
- // TODO: check the script title in path vs the actual script title
- if (!TabManager.scriptsForTab[tabId][scriptId]) { throw new UnixError(unix.ENOENT); }
-
+ const {scriptId} = pathScriptInfo(tabId, path);
const {scriptSource} = await sendDebuggerCommand(tabId, "Debugger.getScriptSource", {scriptId});
return scriptSource;
@@ -313,10 +318,7 @@ router["/tabs/by-id/*/control"] = {
const [tabId, suffix] = [parseInt(pathComponent(path, -4)), pathComponent(path, -1)];
await TabManager.debugTab(tabId); await TabManager.enableDomainForTab(tabId, "Debugger");
- const parts = path.split("_"); const scriptId = parts[0];
- // TODO: check the script title in path vs the actual script title
- if (!TabManager.scriptsForTab[tabId][scriptId]) { throw new UnixError(unix.ENOENT); }
-
+ const {scriptId} = pathScriptInfo(tabId, path);
await sendDebuggerCommand(tabId, "Debugger.setScriptSource", {scriptId, scriptSource: buf});
});
})();
diff --git a/test/test.c b/test/test.c
index 65f7c9d..b9f34b7 100644
--- a/test/test.c
+++ b/test/test.c
@@ -67,6 +67,7 @@ int main() {
assert(matches_regex(readdir(scripts)->d_name, "test\\-script.js$"));
closedir(scripts);
}
+ assert(system("cat ../fs/mnt/tabs/last-focused/debugger/scripts/*test-script.js") == 0);
assert(system("echo remove > ../fs/mnt/tabs/last-focused/control") == 0);
}