Skip to content

Commit 7a10218

Browse files
authored
feat(core): Deprecate urlEncode (#14406)
1 parent 90f958f commit 7a10218

File tree

7 files changed

+23
-8
lines changed

7 files changed

+23
-8
lines changed

docs/migration/draft-v9-migration-guide.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Deprecated `AddRequestDataToEventOptions.transaction`. This option effectively doesn't do anything anymore, and will
88
be removed in v9.
99
- Deprecated `TransactionNamingScheme` type.
10+
- Deprecated `urlEncode`. No replacements.
1011

1112
## `@sentry/core`
1213

packages/core/src/api.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { DsnComponents, DsnLike, SdkInfo } from '@sentry/types';
22
import { dsnToString, makeDsn } from './utils-hoist/dsn';
3-
import { urlEncode } from './utils-hoist/object';
43

54
const SENTRY_API_VERSION = '7';
65

@@ -18,13 +17,21 @@ function _getIngestEndpoint(dsn: DsnComponents): string {
1817

1918
/** Returns a URL-encoded string with auth config suitable for a query string. */
2019
function _encodedAuth(dsn: DsnComponents, sdkInfo: SdkInfo | undefined): string {
21-
return urlEncode({
20+
const params: Record<string, string> = {
21+
sentry_version: SENTRY_API_VERSION,
22+
};
23+
24+
if (dsn.publicKey) {
2225
// We send only the minimum set of required information. See
2326
// https://github.com/getsentry/sentry-javascript/issues/2572.
24-
sentry_key: dsn.publicKey,
25-
sentry_version: SENTRY_API_VERSION,
26-
...(sdkInfo && { sentry_client: `${sdkInfo.name}/${sdkInfo.version}` }),
27-
});
27+
params.sentry_key = dsn.publicKey;
28+
}
29+
30+
if (sdkInfo) {
31+
params.sentry_client = `${sdkInfo.name}/${sdkInfo.version}`;
32+
}
33+
34+
return new URLSearchParams(params).toString();
2835
}
2936

3037
/**

packages/core/src/utils-hoist/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export {
5757
getOriginalFunction,
5858
markFunctionWrapped,
5959
objectify,
60+
// eslint-disable-next-line deprecation/deprecation
6061
urlEncode,
6162
} from './object';
6263
export { basename, dirname, isAbsolute, join, normalizePath, relative, resolve } from './path';

packages/core/src/utils-hoist/object.ts

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ export function getOriginalFunction(func: WrappedFunction): WrappedFunction | un
9090
*
9191
* @param object An object that contains serializable values
9292
* @returns string Encoded
93+
*
94+
* @deprecated This function is deprecated and will be removed in the next major version of the SDK.
9395
*/
9496
export function urlEncode(object: { [key: string]: any }): string {
9597
return Object.keys(object)

packages/core/test/lib/api.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('API', () => {
1818
dsnPublicComponents,
1919
undefined,
2020
undefined,
21-
'https://sentry.io:1234/subpath/api/123/envelope/?sentry_key=abc&sentry_version=7',
21+
'https://sentry.io:1234/subpath/api/123/envelope/?sentry_version=7&sentry_key=abc',
2222
],
2323
['uses `tunnel` value when called with `tunnel` option', dsnPublicComponents, tunnel, undefined, tunnel],
2424
[
@@ -33,7 +33,7 @@ describe('API', () => {
3333
dsnPublicComponents,
3434
undefined,
3535
sdkInfo,
36-
'https://sentry.io:1234/subpath/api/123/envelope/?sentry_key=abc&sentry_version=7&sentry_client=sentry.javascript.browser%2F12.31.12',
36+
'https://sentry.io:1234/subpath/api/123/envelope/?sentry_version=7&sentry_key=abc&sentry_client=sentry.javascript.browser%2F12.31.12',
3737
],
3838
])(
3939
'%s',

packages/core/test/utils-hoist/object.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,17 @@ describe('fill()', () => {
130130

131131
describe('urlEncode()', () => {
132132
test('returns empty string for empty object input', () => {
133+
// eslint-disable-next-line deprecation/deprecation
133134
expect(urlEncode({})).toEqual('');
134135
});
135136

136137
test('returns single key/value pair joined with = sign', () => {
138+
// eslint-disable-next-line deprecation/deprecation
137139
expect(urlEncode({ foo: 'bar' })).toEqual('foo=bar');
138140
});
139141

140142
test('returns multiple key/value pairs joined together with & sign', () => {
143+
// eslint-disable-next-line deprecation/deprecation
141144
expect(urlEncode({ foo: 'bar', pickle: 'rick', morty: '4 2' })).toEqual('foo=bar&pickle=rick&morty=4%202');
142145
});
143146
});

packages/utils/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export {
149149
memoBuilder,
150150
arrayify,
151151
normalizeUrlToBase,
152+
// eslint-disable-next-line deprecation/deprecation
152153
urlEncode,
153154
// eslint-disable-next-line deprecation/deprecation
154155
extractPathForTransaction,

0 commit comments

Comments
 (0)