2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2023-05-01 14:18:45 +00:00
|
|
|
function encodePath(path) {
|
|
|
|
return path
|
|
|
|
? path
|
|
|
|
.split('/')
|
|
|
|
.map((segment) => encodeURIComponent(segment))
|
|
|
|
.join('/')
|
|
|
|
: path;
|
|
|
|
}
|
2019-03-01 16:08:30 +00:00
|
|
|
|
2023-05-01 14:18:45 +00:00
|
|
|
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('/')
|
|
|
|
: '';
|
2019-03-01 16:08:30 +00:00
|
|
|
}
|
|
|
|
|
2023-05-01 14:18:45 +00:00
|
|
|
export { normalizePath, encodePath };
|