summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorjahoti <jahoti@tilde.team>2021-07-21 00:00:00 +0000
committerWojtek Kosior <koszko@koszko.org>2021-07-26 11:09:57 +0200
commit57e4ed2b06d15747b20737bad14bcdd2d73fd8a6 (patch)
tree03219829cf07db1f5d3e695c2380384a17193c8f /common
parent081739e7dcaeed1e0655a49ebdebb02d653d9042 (diff)
downloadbrowser-extension-57e4ed2b06d15747b20737bad14bcdd2d73fd8a6.tar.gz
browser-extension-57e4ed2b06d15747b20737bad14bcdd2d73fd8a6.zip
Remove unnecessary imports of url_item and add a CSP header-parsing function
The parsing function isn't used yet; however, it will eventually be as a less destructive alternative to handling headers as indivisible units.
Diffstat (limited to 'common')
-rw-r--r--common/misc.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/common/misc.js b/common/misc.js
index a59ec14..6af2327 100644
--- a/common/misc.js
+++ b/common/misc.js
@@ -154,6 +154,25 @@ function sign_policy(policy, now, hours_offset) {
return gen_unique(time + policy);
}
+/* Parse a CSP header */
+function parse_csp(csp) {
+ let directive, directive_array;
+ let directives = {};
+ for (directive of csp.split(';')) {
+ directive = directive.trim;
+ if (directive === '')
+ continue;
+
+ directive_array = directive.split(/\s+/);
+ directive = directive_array.shift();
+ /* The "true" case should never occur; nevertheless... */
+ directives[directive] = directive in directives ?
+ directives[directive].concat(directive_array) :
+ directive_array;
+ }
+ return directives;
+}
+
/*
* EXPORTS_START
* EXPORT gen_nonce
@@ -165,5 +184,6 @@ function sign_policy(policy, now, hours_offset) {
* EXPORT nice_name
* EXPORT open_in_settings
* EXPORT is_privileged_url
+ * EXPORT parse_csp
* EXPORTS_END
*/