FIX: ensures a version can be set when no version definde in raw

FIX: ensures a version can be set when no version definde in raw

diff --git a/assets/javascripts/initializers/extend-for-policy.js.es6 b/assets/javascripts/initializers/extend-for-policy.js.es6
index 6bb4a0d..f70f094 100644
--- a/assets/javascripts/initializers/extend-for-policy.js.es6
+++ b/assets/javascripts/initializers/extend-for-policy.js.es6
@@ -269,10 +269,14 @@ function initializePolicy(api) {
         const regexp = new RegExp(`(${setting.name}=)".*?"`, "gm");
         policyString = policyString.replace(regexp, `$1"${newSetting}"`);
       }
-
-      raw = raw.replace(policyRegex, `[policy ${policyString}]`);
     });
 
+    if (!policyString.match(/version/gm)) {
+      policyString = `${policyString} version="1"`;
+    }
+
+    raw = raw.replace(policyRegex, `[policy ${policyString}]`);
+
     return settingReplaced ? raw : false;
   }
 
diff --git a/assets/javascripts/lib/discourse-markdown/policy.js.es6 b/assets/javascripts/lib/discourse-markdown/policy.js.es6
index f911f6c..018c6db 100644
--- a/assets/javascripts/lib/discourse-markdown/policy.js.es6
+++ b/assets/javascripts/lib/discourse-markdown/policy.js.es6
@@ -10,12 +10,15 @@ const rule = {
 
     token.attrs = [
       ["class", "policy"],
-      ["data-group", info.attrs.group],
-      ["data-version", info.attrs.version || 1]
+      ["data-group", info.attrs.group]
     ];
 
+    if (info.attrs["version"]) {
+      token.attrs.push(["data-version", info.attrs.version]);
+    }
+
     if (info.attrs["renew"]) {
-      token.attrs.push(["data-renew", info.attrs["renew"]]);
+      token.attrs.push(["data-renew", info.attrs.renew]);
     }
 
     if (info.attrs.reminder) {

GitHub sha: fa56a8e8

1 Like

Why not use indexOf here instead?

see no particular reason, guess I was doing something more complex at the beginning and ended up just checking on string

1 Like