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 and SimenB committed Mar 9, 2023
1 parent 3f96770 commit 3f25c32
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 @@ -13,6 +13,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

- Support for OpenMetrics and Exemplars
Expand Down
2 changes: 1 addition & 1 deletion lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function escapeLabelValue(str) {
return escapeString(str).replace(/"/g, '\\"');
}
function escapeString(str) {
return str.replace(/\n/g, '\\n').replace(/\\(?!n)/g, '\\\\');
return str.replace(/\\/g, '\\\\').replace(/\n/g, '\\n');
}
function standardizeCounterName(name) {
return name.replace(/_total$/, '');
Expand Down

0 comments on commit 3f25c32

Please sign in to comment.