Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/domain.js

Issue 30002580: Noissue - Abstract hostname normalization (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add tests Created Feb. 8, 2019, 7:26 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/elemHide.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/domain.js
===================================================================
--- a/lib/domain.js
+++ b/lib/domain.js
@@ -35,16 +35,29 @@
for (let key in publicSuffixes)
map.set(key, publicSuffixes[key]);
return map;
}
/**
+ * Normalizes a hostname.
+ * @param {string} hostname
+ * @returns {string}
+ */
+function normalizeHostname(hostname)
+{
+ return (hostname[hostname.length - 1] == "." ?
+ hostname.replace(/\.+$/, "") : hostname).toLowerCase();
+}
+
+exports.normalizeHostname = normalizeHostname;
+
+/**
* Yields all suffixes for a domain. For example, given the domain
* <code>www.example.com</code>, this function yields
* <code>www.example.com</code>, <code>example.com</code>, and
* <code>com</code>, in that order.
*
* @param {string} domain The domain.
* @param {boolean} [includeBlank] Whether to include the blank suffix at the
* end.
« no previous file with comments | « no previous file | lib/elemHide.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld