diff --git a/lib/common/utils.js b/lib/common/utils.js index 9fee091..d842666 100644 --- a/lib/common/utils.js +++ b/lib/common/utils.js @@ -132,6 +132,13 @@ function escapeHtml(str) { // Incoming link can be partially encoded. Convert possible combinations to // unified form. +// +// TODO: Rewrite it. Should use: +// +// - encodeURIComponent for query +// - encodeURI for path +// - (?) punicode for domain mame (but encodeURI seems to work in real world) +// function normalizeLink(url) { var normalized = replaceEntities(url); @@ -141,7 +148,14 @@ function normalizeLink(url) { normalized = decodeURI(normalized); } catch (__) {} - return encodeURI(normalized); + // Encoder throws exception on broken unicode sequence. + // Kill suspicious data for the safety. + // + try { + return encodeURI(normalized); + } catch (__) { + return ''; + } } ////////////////////////////////////////////////////////////////////////////////