Skip to content

Commit

Permalink
Do not add quotes to object names if not necessary when reorganising (#…
Browse files Browse the repository at this point in the history
…282)

Co-authored-by: James Pearson <james.pearson@norriq.com>
  • Loading branch information
jimmymcp and James Pearson committed Jul 12, 2023
1 parent 2120036 commit 364ca34
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/NAVObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,19 @@ export class NAVObject {
if (objectText.indexOf("\"" + this.objectName + "\"") >= 0) {
return objectText.replace(searchPattern, fixedObjectName);
} else {
return objectText.replace(searchPattern, "\"" + fixedObjectName + "\"");
if (this.objectNameRequiresQuotes(fixedObjectName)) {
return objectText.replace(searchPattern, "\"" + fixedObjectName + "\"");
}
else {
return objectText.replace(searchPattern, fixedObjectName);
}
}
}

private objectNameRequiresQuotes(objectName: string): boolean {
return !(/^[A-Za-z0-9]+$/.test(objectName));
}

private escapeRegExp(str) {
// Ref. https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
Expand Down

0 comments on commit 364ca34

Please sign in to comment.