open-vault/ui/app/utils/path-encoding-helpers.js
Chelsea Shaw b743ada5ab
UI: fix secret with % in path (#20430)
* Use encode/decode uri component instead of route-recognizer. Fixes #11616

* Remove route-recognizer explicit dependency

* Add changelog
2023-05-01 09:18:45 -05:00

28 lines
623 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
function encodePath(path) {
return path
? path
.split('/')
.map((segment) => encodeURIComponent(segment))
.join('/')
: path;
}
function normalizePath(path) {
// Unlike normalizePath from route-recognizer, this method assumes
// we do not have percent-encoded data octets as defined in
// https://datatracker.ietf.org/doc/html/rfc3986
return path
? path
.split('/')
.map((segment) => decodeURIComponent(segment))
.join('/')
: '';
}
export { normalizePath, encodePath };