MCPcopy
hub / github.com/vitejs/vite / extractHostnamesFromSubjectAltName

Function extractHostnamesFromSubjectAltName

packages/vite/src/node/utils.ts:1080–1116  ·  view source on GitHub ↗
(
  subjectAltName: string,
)

Source from the content-addressed store, hash-verified

1078}
1079
1080export function extractHostnamesFromSubjectAltName(
1081 subjectAltName: string,
1082): string[] {
1083 const hostnames: string[] = []
1084 let remaining = subjectAltName
1085 while (remaining) {
1086 const nameEndIndex = remaining.indexOf(':')
1087 const name = remaining.slice(0, nameEndIndex)
1088 remaining = remaining.slice(nameEndIndex + 1)
1089 if (!remaining) break
1090
1091 const isQuoted = remaining[0] === '"'
1092 let value: string
1093 if (isQuoted) {
1094 const endQuoteIndex = remaining.indexOf('"', 1)
1095 value = JSON.parse(remaining.slice(0, endQuoteIndex + 1))
1096 remaining = remaining.slice(endQuoteIndex + 1)
1097 } else {
1098 const maybeEndIndex = remaining.indexOf(',')
1099 const endIndex = maybeEndIndex === -1 ? remaining.length : maybeEndIndex
1100 value = remaining.slice(0, endIndex)
1101 remaining = remaining.slice(endIndex)
1102 }
1103 remaining = remaining.slice(/* for , */ 1).trimStart()
1104
1105 if (
1106 name === 'DNS' &&
1107 // [::1] might be included but skip it as it's already included as a local address
1108 value !== '[::1]' &&
1109 // skip *.IPv4 addresses, which is invalid
1110 !(value.startsWith('*.') && net.isIPv4(value.slice(2)))
1111 ) {
1112 hostnames.push(value.replace('*', 'vite'))
1113 }
1114 }
1115 return hostnames
1116}
1117
1118export function arraify<T>(target: T | T[]): T[] {
1119 return Array.isArray(target) ? target : [target]

Callers 2

utils.spec.tsFile · 0.90

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected