Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about URL and URLSearchParams not being spec-complaint #30188

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Libraries/Blob/URL.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

const Blob = require('./Blob');
const warnOnce = require('../Utilities/warnOnce');

import NativeBlobModule from './NativeBlobModule';

Expand Down Expand Up @@ -55,6 +56,13 @@ export class URLSearchParams {
_searchParams = [];

constructor(params: any) {
warnOnce(
'urlsearchparams-warn-non-spec-compliant',
'URLSearchParams from React Native is not spec-compliant. ' +
"You should use a spec-compliant polyfill like 'react-native-url-polyfill'. " +
'See https://github.com/charpeni/react-native-url-polyfill',
);

if (typeof params === 'object') {
Object.keys(params).forEach(key => this.append(key, params[key]));
}
Expand Down Expand Up @@ -114,6 +122,13 @@ export class URL {
_searchParamsInstance = null;

static createObjectURL(blob: Blob) {
warnOnce(
'url-warn-non-spec-compliant',
'URL from React Native is not spec-compliant. ' +
"You should use a spec-compliant polyfill like 'react-native-url-polyfill'. " +
'See https://github.com/charpeni/react-native-url-polyfill',
);

if (BLOB_URL_PREFIX === null) {
throw new Error('Cannot create URL for blob!');
}
Expand All @@ -125,6 +140,13 @@ export class URL {
}

constructor(url: string, base: string) {
warnOnce(
'url-warn-non-spec-compliant',
'URL from React Native is not spec-compliant. ' +
"You should use a spec-compliant polyfill like 'react-native-url-polyfill'. " +
'See https://github.com/charpeni/react-native-url-polyfill',
);

let baseUrl = null;
if (!base || validateBaseUrl(url)) {
this._url = url;
Expand Down