summaryrefslogtreecommitdiff
path: root/shared/logger/node_modules/@sentry/utils/esm/url.js
diff options
context:
space:
mode:
authorrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
committerrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
commitbce557cc2dc767628bed6aac87301a1be7c5431b (patch)
treeb51a051228d01fe3306cd7626d4a96768aadb944 /shared/logger/node_modules/@sentry/utils/esm/url.js
init commit
Diffstat (limited to 'shared/logger/node_modules/@sentry/utils/esm/url.js')
-rw-r--r--shared/logger/node_modules/@sentry/utils/esm/url.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/shared/logger/node_modules/@sentry/utils/esm/url.js b/shared/logger/node_modules/@sentry/utils/esm/url.js
new file mode 100644
index 0000000..2e0bd40
--- /dev/null
+++ b/shared/logger/node_modules/@sentry/utils/esm/url.js
@@ -0,0 +1,72 @@
+/**
+ * Parses string form of URL into an object
+ * // borrowed from https://tools.ietf.org/html/rfc3986#appendix-B
+ * // intentionally using regex and not <a/> href parsing trick because React Native and other
+ * // environments where DOM might not be available
+ * @returns parsed URL object
+ */
+function parseUrl(url) {
+ if (!url) {
+ return {};
+ }
+
+ const match = url.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);
+
+ if (!match) {
+ return {};
+ }
+
+ // coerce to undefined values to empty string so we don't get 'undefined'
+ const query = match[6] || '';
+ const fragment = match[8] || '';
+ return {
+ host: match[4],
+ path: match[5],
+ protocol: match[2],
+ search: query,
+ hash: fragment,
+ relative: match[5] + query + fragment, // everything minus origin
+ };
+}
+
+/**
+ * Strip the query string and fragment off of a given URL or path (if present)
+ *
+ * @param urlPath Full URL or path, including possible query string and/or fragment
+ * @returns URL or path without query string or fragment
+ */
+function stripUrlQueryAndFragment(urlPath) {
+ // eslint-disable-next-line no-useless-escape
+ return urlPath.split(/[\?#]/, 1)[0];
+}
+
+/**
+ * Returns number of URL segments of a passed string URL.
+ */
+function getNumberOfUrlSegments(url) {
+ // split at '/' or at '\/' to split regex urls correctly
+ return url.split(/\\?\//).filter(s => s.length > 0 && s !== ',').length;
+}
+
+/**
+ * Takes a URL object and returns a sanitized string which is safe to use as span description
+ * see: https://develop.sentry.dev/sdk/data-handling/#structuring-data
+ */
+function getSanitizedUrlString(url) {
+ const { protocol, host, path } = url;
+
+ const filteredHost =
+ (host &&
+ host
+ // Always filter out authority
+ .replace(/^.*@/, '[filtered]:[filtered]@')
+ // Don't show standard :80 (http) and :443 (https) ports to reduce the noise
+ .replace(':80', '')
+ .replace(':443', '')) ||
+ '';
+
+ return `${protocol ? `${protocol}://` : ''}${filteredHost}${path}`;
+}
+
+export { getNumberOfUrlSegments, getSanitizedUrlString, parseUrl, stripUrlQueryAndFragment };
+//# sourceMappingURL=url.js.map