Skip to content

Commit

Permalink
Universal IPv6 regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed Sep 11, 2016
1 parent 68fea9c commit d28435f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Expand Up @@ -59,8 +59,11 @@ function getCommonNames (buffer, encoding) {
}

function toRegEx (names) {
const domains = { wc: [], single: [], both: [] }
const domains = { wc: [], single: [], both: [], ip6: [] }
names.forEach((e) => {
if (/^\[?[0-9a-f:]+\]?$/.test(e)) {
return domains.ip6.push(e)
}
var wc = false
if (e[0] === '*') {
wc = true
Expand All @@ -78,6 +81,11 @@ function toRegEx (names) {
return false
})
const entries = []
if (domains.ip6.length > 0) {
entries.push('(\\[?' + domains.ip6.map((e) => {
return e.replace(/:0([^0])/g, ':0?$1').replace(/:[0:]+:/, ':[0:]*:').replace(/:0{2,}/g, ':0*')
}).join('\\]?)|(\\[?') + '\\]?)')
}
if (domains.single.length > 0) {
entries.push(domains.single.join('|'))
}
Expand Down

0 comments on commit d28435f

Please sign in to comment.