diff --git a/CHANGELOG.md b/CHANGELOG.md index 36a619192832..7432e7989b96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.9.5 (Unreleased) + +BUG FIXES: + + * ui: Fixed links containing IPv6 addresses to include required square brackets [[GH-6007](https://github.com/hashicorp/nomad/pull/6007)] + ## 0.9.4 (July 30, 2019) IMPROVEMENTS: diff --git a/ui/app/serializers/network.js b/ui/app/serializers/network.js index 00fea3be8080..56410188eb14 100644 --- a/ui/app/serializers/network.js +++ b/ui/app/serializers/network.js @@ -1,4 +1,5 @@ import ApplicationSerializer from './application'; +import isIp from 'is-ip'; export default ApplicationSerializer.extend({ attrs: { @@ -6,4 +7,14 @@ export default ApplicationSerializer.extend({ ip: 'IP', mbits: 'MBits', }, + + normalize(typeHash, hash) { + const ip = hash.IP; + + if (isIp.v6(ip)) { + hash.IP = `[${ip}]`; + } + + return this._super(...arguments); + }, }); diff --git a/ui/package.json b/ui/package.json index 85f0f2009fff..4a712fba5f0c 100644 --- a/ui/package.json +++ b/ui/package.json @@ -88,6 +88,7 @@ "flat": "^4.0.0", "fuse.js": "^3.4.4", "husky": "^1.3.1", + "is-ip": "^3.1.0", "ivy-codemirror": "^2.1.0", "lint-staged": "^8.1.5", "loader.js": "^4.7.0", diff --git a/ui/tests/unit/serializers/network-test.js b/ui/tests/unit/serializers/network-test.js new file mode 100644 index 000000000000..8c5d614de6b4 --- /dev/null +++ b/ui/tests/unit/serializers/network-test.js @@ -0,0 +1,31 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import NetworkModel from 'nomad-ui/models/network'; + +module('Unit | Serializer | Network', function(hooks) { + setupTest(hooks); + hooks.beforeEach(function() { + this.store = this.owner.lookup('service:store'); + this.subject = () => this.store.serializerFor('network'); + }); + + test('v4 IPs are passed through', async function(assert) { + const ip = '10.0.13.12'; + const original = { + IP: ip, + }; + + const { data } = this.subject().normalize(NetworkModel, original); + assert.equal(data.attributes.ip, ip); + }); + + test('v6 IPs are wrapped in square brackets', async function(assert) { + const ip = '2001:0dac:aba3:0000:0000:8a2e:0370:7334'; + const original = { + IP: ip, + }; + + const { data } = this.subject().normalize(NetworkModel, original); + assert.equal(data.attributes.ip, `[${ip}]`); + }); +}); diff --git a/ui/yarn.lock b/ui/yarn.lock index f513bdaa918d..8f68c8e4b313 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -6569,6 +6569,11 @@ invert-kv@^1.0.0: resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6" integrity sha1-EEqOSqym09jNFXqO+L+rLXo//bY= +ip-regex@^4.0.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-4.1.0.tgz#5ad62f685a14edb421abebc2fff8db94df67b455" + integrity sha512-pKnZpbgCTfH/1NLIlOduP/V+WRXzC2MOz3Qo8xmxk8C5GudJLgK5QyLVXOSWy3ParAH7Eemurl3xjv/WXYFvMA== + ipaddr.js@1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.8.0.tgz#eaa33d6ddd7ace8f7f6fe0c9ca0440e706738b1e" @@ -6719,6 +6724,13 @@ is-glob@^4.0.0: dependencies: is-extglob "^2.1.1" +is-ip@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/is-ip/-/is-ip-3.1.0.tgz#2ae5ddfafaf05cb8008a62093cf29734f657c5d8" + integrity sha512-35vd5necO7IitFPjd/YBeqwWnyDWbuLH9ZXQdMfDA8TEo7pv5X8yfrvVO3xbJbLUlERCMvf6X0hTUamQxCYJ9Q== + dependencies: + ip-regex "^4.0.0" + is-number@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195"