2017-06-21 20:56:19 +00:00
|
|
|
import {parse as urlParse} from 'url';
|
2017-06-21 21:20:42 +00:00
|
|
|
|
2017-06-21 20:56:19 +00:00
|
|
|
const WILDCARD_CHARACTER = '*';
|
|
|
|
const WILDCARD_SUBSTITUTION = Math.random().toString().split('.')[1];
|
|
|
|
const WILDCARD_SUBSTITUTION_PATTERN = new RegExp(`${WILDCARD_SUBSTITUTION}`, 'g');
|
|
|
|
|
|
|
|
export default function certificateUrlParse (url) {
|
|
|
|
if (url.indexOf(WILDCARD_CHARACTER) === -1) {
|
|
|
|
return urlParse(url);
|
|
|
|
} else {
|
|
|
|
const parsed = urlParse(url.replace(/\*/g, WILDCARD_SUBSTITUTION));
|
2017-06-21 21:20:42 +00:00
|
|
|
parsed.hostname = _reinstateWildcards(parsed.hostname);
|
|
|
|
parsed.host = _reinstateWildcards(parsed.host);
|
|
|
|
parsed.href = _reinstateWildcards(parsed.href);
|
2017-11-04 21:00:16 +00:00
|
|
|
parsed.port = _reinstateWildcards(parsed.port);
|
2017-06-21 20:56:19 +00:00
|
|
|
|
|
|
|
return parsed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:20:42 +00:00
|
|
|
function _reinstateWildcards (string) {
|
2017-06-21 20:56:19 +00:00
|
|
|
if (string) {
|
|
|
|
return string.replace(WILDCARD_SUBSTITUTION_PATTERN, WILDCARD_CHARACTER);
|
|
|
|
} else {
|
|
|
|
return string;
|
|
|
|
}
|
2017-06-21 21:20:42 +00:00
|
|
|
}
|