HSTS: Improved tokenization (#3277)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
diff --git a/components/prism-hsts.js b/components/prism-hsts.js
index 4d56433..e2276a1 100644
--- a/components/prism-hsts.js
+++ b/components/prism-hsts.js
@@ -6,15 +6,9 @@
Prism.languages.hsts = {
'directive': {
- pattern: /\b(?:max-age=|includeSubDomains|preload)/,
- alias: 'keyword'
+ pattern: /\b(?:includeSubDomains|max-age|preload)(?=[\s;=]|$)/i,
+ alias: 'property'
},
- 'safe': {
- pattern: /\b\d{8,}\b/,
- alias: 'selector'
- },
- 'unsafe': {
- pattern: /\b\d{1,7}\b/,
- alias: 'function'
- }
+ 'operator': /=/,
+ 'punctuation': /;/
};
diff --git a/components/prism-hsts.min.js b/components/prism-hsts.min.js
index b92d756..3faeef2 100644
--- a/components/prism-hsts.min.js
+++ b/components/prism-hsts.min.js
@@ -1 +1 @@
-Prism.languages.hsts={directive:{pattern:/\b(?:max-age=|includeSubDomains|preload)/,alias:"keyword"},safe:{pattern:/\b\d{8,}\b/,alias:"selector"},unsafe:{pattern:/\b\d{1,7}\b/,alias:"function"}};
\ No newline at end of file
+Prism.languages.hsts={directive:{pattern:/\b(?:includeSubDomains|max-age|preload)(?=[\s;=]|$)/i,alias:"property"},operator:/=/,punctuation:/;/};
\ No newline at end of file
diff --git a/tests/languages/hsts/max-age_feature.test b/tests/languages/hsts/max-age_feature.test
new file mode 100644
index 0000000..55d6453
--- /dev/null
+++ b/tests/languages/hsts/max-age_feature.test
@@ -0,0 +1,27 @@
+max-age=0;
+max-age="0";
+max-age=31536000;
+max-age="31536000"
+
+----------------------------------------------------
+
+[
+ ["directive", "max-age"],
+ ["operator", "="],
+ "0",
+ ["punctuation", ";"],
+
+ ["directive", "max-age"],
+ ["operator", "="],
+ "\"0\"",
+ ["punctuation", ";"],
+
+ ["directive", "max-age"],
+ ["operator", "="],
+ "31536000",
+ ["punctuation", ";"],
+
+ ["directive", "max-age"],
+ ["operator", "="],
+ "\"31536000\""
+]
diff --git a/tests/languages/hsts/safe_maxage_feature.test b/tests/languages/hsts/safe_maxage_feature.test
deleted file mode 100644
index 6797fff..0000000
--- a/tests/languages/hsts/safe_maxage_feature.test
+++ /dev/null
@@ -1,12 +0,0 @@
-max-age=31536000
-
-----------------------------------------------------
-
-[
- ["directive", "max-age="],
- ["safe", "31536000"]
-]
-
-----------------------------------------------------
-
-Checks for HSTS with a "safe" max-age.
diff --git a/tests/languages/hsts/unsafe_maxage_feature.test b/tests/languages/hsts/unsafe_maxage_feature.test
deleted file mode 100644
index dba69dc..0000000
--- a/tests/languages/hsts/unsafe_maxage_feature.test
+++ /dev/null
@@ -1,12 +0,0 @@
-max-age=123
-
-----------------------------------------------------
-
-[
- ["directive", "max-age="],
- ["unsafe", "123"]
-]
-
-----------------------------------------------------
-
-Checks for HSTS with an "unsafe" max-age.