@automattic/wpcom-checkout
Version:
Functions and components used by WordPress.com checkout.
26 lines • 1.29 kB
JavaScript
;
// Some product slugs or meta contain slashes which will break the URL, so we
// encode them first. We cannot use encodeURIComponent because the calypso
// router seems to break if the trailing part of the URL contains an encoded
// slash (eg: /checkout/example.com/foo%2Fbar breaks routing). We cannot use
// the same characters for encoding as for decoding if they are UTF-8 encoded
// because they will already be decoded by the time the decoding takes place.
//
// If all of that is confusing, see the tests for these functions to understand
// how they will be used.
//
// If this is ever changed, please make sure to also change the code that
// generates renewal emails on the backend, because it uses the same encoding!
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodeProductForUrl = encodeProductForUrl;
exports.decodeProductFromUrl = decodeProductFromUrl;
const slashForEncoding = '%25';
const slashForDecoding = '%';
function encodeProductForUrl(slug) {
return slug.replace(/\//g, slashForEncoding);
}
function decodeProductFromUrl(slug) {
// This should really use String.prototype.replaceAll but it's yet not fully supported
return slug.split(slashForDecoding).join('/');
}
//# sourceMappingURL=product-url-encoding.js.map