about summary refs log tree commit diff
path: root/app/javascript/mastodon/utils
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-07-30 12:13:29 +0200
committerEugen Rochko <eugen@zeonfederated.com>2019-07-30 12:13:29 +0200
commitb31b232edfcc7f04acf828bf6829ab716b290692 (patch)
tree030c02b6f0ab4cf2d76e87dfeaf41b815555b778 /app/javascript/mastodon/utils
parent78144f4c7923d502cc86b322f044e740e4a8fa8a (diff)
Change links in webUI to rewrite misleading links (#11426)
* [WiP] Show host for “misleading” links

* Disallow misleading targets which domain names are prefixes of link text

* Move decodeIDNA to app/javascript/mastodon/utils

* Add support for international domain names

* Change link origin tag color to darker text color

* Handle links to domains starting with www. as shortened by Mastodon

* [WiP] Ignore links that cannot be misread as URLs, rewrite other links
Diffstat (limited to 'app/javascript/mastodon/utils')
-rw-r--r--app/javascript/mastodon/utils/idna.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/app/javascript/mastodon/utils/idna.js b/app/javascript/mastodon/utils/idna.js
new file mode 100644
index 000000000..efab5bacf
--- /dev/null
+++ b/app/javascript/mastodon/utils/idna.js
@@ -0,0 +1,10 @@
+import punycode from 'punycode';
+
+const IDNA_PREFIX = 'xn--';
+
+export const decode = domain => {
+  return domain
+    .split('.')
+    .map(part => part.indexOf(IDNA_PREFIX) === 0 ? punycode.decode(part.slice(IDNA_PREFIX.length)) : part)
+    .join('.');
+};