MCPcopy
hub / github.com/mongodb/node-mongodb-native / hostMatchesWildcards

Function hostMatchesWildcards

src/utils.ts:70–95  ·  view source on GitHub ↗
(host: string, wildcards: string[])

Source from the content-addressed store, hash-verified

68 * of domain wildcards.
69 */
70export function hostMatchesWildcards(host: string, wildcards: string[]): boolean {
71 for (const wildcard of wildcards) {
72 // Exact match always wins
73 if (host === wildcard) {
74 return true;
75 }
76
77 // Wildcard match with leading *.
78 if (wildcard.startsWith('*.')) {
79 const suffix = wildcard.substring(2);
80 // Exact match or strict subdomain match
81 if (host === suffix || host.endsWith(`.${suffix}`)) {
82 return true;
83 }
84 }
85 // Wildcard match with leading */
86 if (wildcard.startsWith('*/')) {
87 const suffix = wildcard.substring(2);
88 // Exact match or strict subpath match
89 if (host === suffix || host.endsWith(`/${suffix}`)) {
90 return true;
91 }
92 }
93 }
94 return false;
95}
96
97/**
98 * Ensure Hint field is in a shape we expect:

Callers 2

_connectMethod · 0.90
utils.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected