Merge pull request #315 from DotJoshJohnson/bug/271-xml-entity-escaping

Add &amp, ", and ' Entities
This commit is contained in:
Josh Johnson 2020-07-02 00:56:16 -04:00 committed by GitHub
commit 3e20dd05c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -19,7 +19,13 @@ export function textToXml(textEditor: TextEditor): void {
);
}
const txt = textEditor.document.getText(new Range(selection.start, selection.end));
const transformed = txt.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
const transformed = txt
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&amp;/g, "&")
.replace(/&quot;/g, '"')
.replace(/&apos;/g, "'");
textEdit.replace(selection, transformed);
});
});

View File

@ -19,7 +19,13 @@ export function xmlToText(textEditor: TextEditor): void {
);
}
const txt = textEditor.document.getText(new Range(selection.start, selection.end));
const transformed = txt.replace(/</g, "&lt;").replace(/>/g, "&gt;");
const transformed = txt
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/&/g, "&amp;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&apos;");
textEdit.replace(selection, transformed);
});
});