[79a0317] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | function findRelation_upToPath(urlObj, siteUrlObj, options)
|
---|
| 4 | {
|
---|
| 5 | // Path- or root-relative URL
|
---|
| 6 | var pathOnly = urlObj.extra.hrefInfo.minimumPathOnly;
|
---|
| 7 |
|
---|
| 8 | // Matching scheme, scheme-relative or path-only
|
---|
| 9 | var minimumScheme = (urlObj.scheme===siteUrlObj.scheme || !urlObj.scheme);
|
---|
| 10 |
|
---|
| 11 | // Matching auth, ignoring auth or path-only
|
---|
| 12 | var minimumAuth = minimumScheme && (urlObj.auth===siteUrlObj.auth || options.removeAuth || pathOnly);
|
---|
| 13 |
|
---|
| 14 | // Matching host or path-only
|
---|
| 15 | var www = options.ignore_www ? "stripped" : "full";
|
---|
| 16 | var minimumHost = minimumAuth && (urlObj.host[www]===siteUrlObj.host[www] || pathOnly);
|
---|
| 17 |
|
---|
| 18 | // Matching port or path-only
|
---|
| 19 | var minimumPort = minimumHost && (urlObj.port===siteUrlObj.port || pathOnly);
|
---|
| 20 |
|
---|
| 21 | urlObj.extra.relation.minimumScheme = minimumScheme;
|
---|
| 22 | urlObj.extra.relation.minimumAuth = minimumAuth;
|
---|
| 23 | urlObj.extra.relation.minimumHost = minimumHost;
|
---|
| 24 | urlObj.extra.relation.minimumPort = minimumPort;
|
---|
| 25 |
|
---|
| 26 | urlObj.extra.relation.maximumScheme = !minimumScheme || minimumScheme && !minimumAuth;
|
---|
| 27 | urlObj.extra.relation.maximumAuth = !minimumScheme || minimumScheme && !minimumHost;
|
---|
| 28 | urlObj.extra.relation.maximumHost = !minimumScheme || minimumScheme && !minimumPort;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | function findRelation_pathOn(urlObj, siteUrlObj, options)
|
---|
| 34 | {
|
---|
| 35 | var queryOnly = urlObj.extra.hrefInfo.minimumQueryOnly;
|
---|
| 36 | var hashOnly = urlObj.extra.hrefInfo.minimumHashOnly;
|
---|
| 37 | var empty = urlObj.extra.hrefInfo.empty; // not required, but self-documenting
|
---|
| 38 |
|
---|
| 39 | // From upToPath()
|
---|
| 40 | var minimumPort = urlObj.extra.relation.minimumPort;
|
---|
| 41 | var minimumScheme = urlObj.extra.relation.minimumScheme;
|
---|
| 42 |
|
---|
| 43 | // Matching port and path
|
---|
| 44 | var minimumPath = minimumPort && urlObj.path.absolute.string===siteUrlObj.path.absolute.string;
|
---|
| 45 |
|
---|
| 46 | // Matching resource or query/hash-only or empty
|
---|
| 47 | var matchingResource = (urlObj.resource===siteUrlObj.resource || !urlObj.resource && siteUrlObj.extra.resourceIsIndex) || (options.removeDirectoryIndexes && urlObj.extra.resourceIsIndex && !siteUrlObj.resource);
|
---|
| 48 | var minimumResource = minimumPath && (matchingResource || queryOnly || hashOnly || empty);
|
---|
| 49 |
|
---|
| 50 | // Matching query or hash-only/empty
|
---|
| 51 | var query = options.removeEmptyQueries ? "stripped" : "full";
|
---|
| 52 | var urlQuery = urlObj.query.string[query];
|
---|
| 53 | var siteUrlQuery = siteUrlObj.query.string[query];
|
---|
| 54 | var minimumQuery = (minimumResource && !!urlQuery && urlQuery===siteUrlQuery) || ((hashOnly || empty) && !urlObj.extra.hrefInfo.separatorOnlyQuery);
|
---|
| 55 |
|
---|
| 56 | var minimumHash = minimumQuery && urlObj.hash===siteUrlObj.hash;
|
---|
| 57 |
|
---|
| 58 | urlObj.extra.relation.minimumPath = minimumPath;
|
---|
| 59 | urlObj.extra.relation.minimumResource = minimumResource;
|
---|
| 60 | urlObj.extra.relation.minimumQuery = minimumQuery;
|
---|
| 61 | urlObj.extra.relation.minimumHash = minimumHash;
|
---|
| 62 |
|
---|
| 63 | urlObj.extra.relation.maximumPort = !minimumScheme || minimumScheme && !minimumPath;
|
---|
| 64 | urlObj.extra.relation.maximumPath = !minimumScheme || minimumScheme && !minimumResource;
|
---|
| 65 | urlObj.extra.relation.maximumResource = !minimumScheme || minimumScheme && !minimumQuery;
|
---|
| 66 | urlObj.extra.relation.maximumQuery = !minimumScheme || minimumScheme && !minimumHash;
|
---|
| 67 | urlObj.extra.relation.maximumHash = !minimumScheme || minimumScheme && !minimumHash; // there's nothing after hash, so it's the same as maximumQuery
|
---|
| 68 |
|
---|
| 69 | // Matching path and/or resource with existing but non-matching site query
|
---|
| 70 | urlObj.extra.relation.overridesQuery = minimumPath && urlObj.extra.relation.maximumResource && !minimumQuery && !!siteUrlQuery;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | module.exports =
|
---|
| 76 | {
|
---|
| 77 | pathOn: findRelation_pathOn,
|
---|
| 78 | upToPath: findRelation_upToPath
|
---|
| 79 | };
|
---|