npm-groovy-lint 11.1.2-beta202311021422.0 → 11.1.2-beta202311021635.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ const rule = {
8
8
  variables: [
9
9
  {
10
10
  name: "STRING",
11
- regex: /The String '(.*)' can be wrapped in single quotes instead of double quotes/
11
+ regex: /The String '([\s\S]*)' can be wrapped in single quotes instead of double quotes/
12
12
  }
13
13
  ],
14
14
  range: {
package/lib/utils.js CHANGED
@@ -128,17 +128,34 @@ function evaluateRangeFromLine(errItem, allLines) {
128
128
  return getDefaultRange(allLines, errItem);
129
129
  }
130
130
 
131
+ // escapeMessage escapes a value as retrieved from CodeNarc
132
+ // from the "display name" so it matches the original source.
133
+ // See issue: https://github.com/CodeNarc/CodeNarc/issues/749
134
+ // Escaping as per: https://groovy-lang.org/syntax.html#_escaping_special_characters
135
+ function escapeValue(s) {
136
+ return s
137
+ .replace(/\\/g, "\\\\")
138
+ .replace(/[\b]/g, "\\b") // Class so \b is not a word boundary.
139
+ .replace(/\f/g, "\\f")
140
+ .replace(/\n/g, "\\n")
141
+ .replace(/\r/g, "\\r")
142
+ .replace(/\t/g, "\\t")
143
+ .replace(/\v/g, "\\v")
144
+ .replace(/'/g, "\\'")
145
+ .replace(/"/g, '\\"');
146
+ }
147
+
131
148
  // Evaluate variables from messages
132
149
  function evaluateVariables(variableDefs, msg) {
133
150
  const evaluatedVars = [];
134
151
  for (const varDef of variableDefs || []) {
135
152
  // regex
136
153
  if (varDef.regex) {
137
- msg = msg.replace(/\n/g, "\\n").replace(/\r/g, "\\r");
138
154
  const regexRes = msg.match(varDef.regex);
139
155
  if (regexRes && regexRes.length > 1) {
140
156
  const regexPos = varDef.regexPos || 1;
141
- const value = decodeHtml(regexRes[regexPos]);
157
+ let value = decodeHtml(regexRes[regexPos]);
158
+ value = escapeValue(value);
142
159
  const varValue =
143
160
  varDef.type && varDef.type === "number"
144
161
  ? parseInt(value, 10)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-groovy-lint",
3
- "version": "11.1.2-beta202311021422.0",
3
+ "version": "11.1.2-beta202311021635.0",
4
4
  "description": "Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files",
5
5
  "main": "index.js",
6
6
  "scripts": {