Commit 3d708b9780b68bdc60e638ddad9156d7f4efa92b

Michael Schmidt 2021-12-18T13:27:08

HSTS: Improved tokenization (#3277)

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.