import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
+import punycode from 'punycode'
-const hostStyle = {
- display: 'block',
- marginTop: '5px',
- fontSize: '13px'
-};
+const IDNA_PREFIX = 'xn--';
+
+const decodeIDNA = domain => {
+ return domain
+ .split('.')
+ .map(part => part.indexOf(IDNA_PREFIX) === 0 ? punycode.decode(part.slice(IDNA_PREFIX.length)) : part)
+ .join('.');
+}
const getHostname = url => {
const parser = document.createElement('a');
}
if (provider.length < 1) {
- provider = getHostname(card.get('url'))
+ provider = decodeIDNA(getHostname(card.get('url')));
}
return (
<div className='status-card__content'>
<strong className='status-card__title' title={card.get('title')}>{card.get('title')}</strong>
<p className='status-card__description'>{(card.get('description') || '').substring(0, 50)}</p>
- <span className='status-card__host' style={hostStyle}>{provider}</span>
+ <span className='status-card__host'>{provider}</span>
</div>
</a>
);
return if url.nil?
+ url = Addressable::URI.parse(url).normalize.to_s
card = PreviewCard.where(status: status).first_or_initialize(status: status, url: url)
attempt_opengraph(card, url) unless attempt_oembed(card, url)
end
"postcss-smart-import": "^0.6.12",
"precss": "^1.4.0",
"prop-types": "^15.5.8",
+ "punycode": "^2.1.0",
"rails-erb-loader": "^5.0.0",
"react": "^15.5.4",
"react-addons-perf": "^15.4.2",
version "1.4.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"
+punycode@^2.1.0:
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.0.tgz#5f863edc89b96db09074bad7947bf09056ca4e7d"
+
q@^1.1.2:
version "1.4.1"
resolved "https://registry.yarnpkg.com/q/-/q-1.4.1.tgz#55705bcd93c5f3673530c2c2cbc0c2b3addc286e"