Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

hash_util: Convert object characterToBeReplaced object to map.

Anders Kaseorgfe28ecb71dfc
diff --git a/static/js/hash_util.js b/static/js/hash_util.js
index 8ec879e8e85..73b6c5dfec1 100644
--- a/static/js/hash_util.js
+++ b/static/js/hash_util.js
@@ -22,17 +22,18 @@ export function get_hash_section(hash) {
return parts[1] || "";
}
+const hashReplacements = new Map([
+ ["%", "."],
+ ["(", ".28"],
+ [")", ".29"],
+ [".", ".2E"],
+]);
+
// Some browsers zealously URI-decode the contents of
// window.location.hash. So we hide our URI-encoding
// by replacing % with . (like MediaWiki).
export function encodeHashComponent(str) {
- const characterToBeReplaced = {
- ".": ".2E",
- "%": ".",
- "(": ".28",
- ")": ".29",
- };
- return encodeURIComponent(str).replace(/[%().]/g, (matched) => characterToBeReplaced[matched]);
+ return encodeURIComponent(str).replace(/[%().]/g, (matched) => hashReplacements.get(matched));
}
export function encode_operand(operator, operand) {