Skip to content

Commit

Permalink
perf: swap order of escape regexes to avoid lookahead (#546)
Browse files Browse the repository at this point in the history
* swap regex order to avoid lookahead

* changelog

* changelog formatting apparently
  • Loading branch information
ngavalas authored Mar 8, 2023
1 parent 4ddf9a2 commit 199b7d1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Refactor `escapeString` helper in `lib/registry.js` to improve performance and
avoid an unnecessarily complex regex.

### Added

## [14.2.0] - 2023-03-06
Expand Down
2 changes: 1 addition & 1 deletion lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const { getValueAsString } = require('./util');

function escapeString(str) {
return str.replace(/\n/g, '\\n').replace(/\\(?!n)/g, '\\\\');
return str.replace(/\\/g, '\\\\').replace(/\n/g, '\\n');
}
function escapeLabelValue(str) {
if (typeof str !== 'string') {
Expand Down

0 comments on commit 199b7d1

Please sign in to comment.