Skip to content

Commit 082c032

Browse files
committed
fix: “smaller” normalize url + normalizeUrls && normalizeUrlsOptions options
1 parent 8f32fd4 commit 082c032

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"lerna": "^4.0.0",
4242
"nativescript-vue": "^2.9.0",
4343
"ng-packagr": "~12.2.0",
44+
"normalize-url": "^7.0.2",
4445
"prettier": "^2.3.2",
4546
"promise-polyfill": "^8.2.0",
4647
"react-nativescript": "^2.2.0",
@@ -55,7 +56,6 @@
5556
"tslib": "^2.3.0",
5657
"typedoc": "^0.21.5",
5758
"typescript": "~4.3.5",
58-
"url": "^0.11.0",
5959
"vue": "^2.6.14",
6060
"yargs": "^17.1.0"
6161
},

packages/webview-rtc/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
2+
pnpm-global/
23
src/
34
bin/
45
hooks/

packages/webview/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
2+
pnpm-global/
23
src/
34
bin/
45
hooks/

packages/webview/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@
7070
"license": "Apache-2.0",
7171
"readmeFilename": "README.md",
7272
"dependencies": {
73-
"url": "^0.11.0"
73+
"normalize-url": "^7.0.2"
7474
}
7575
}

src/webview/index.common.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { CSSType, ContainerView, EventData, File, Property, Trace, booleanConverter, knownFolders, path } from '@nativescript/core';
44
import { isEnabledProperty } from '@nativescript/core/ui/core/view';
55
import { metadataViewPort, promisePolyfill, webViewBridge } from './nativescript-webview-bridge-loader';
6-
import * as URL from 'url';
6+
import normalizeUrl from 'normalize-url';
77

88
export interface ViewPortProperties {
99
width?: number | 'device-width';
@@ -58,6 +58,7 @@ export const webConsoleProperty = new Property<WebViewExtBase, boolean>({
5858
valueConverter: booleanConverter
5959
});
6060

61+
6162
export const displayZoomControlsProperty = new Property<WebViewExtBase, boolean>({
6263
name: 'displayZoomControls',
6364
defaultValue: true,
@@ -101,6 +102,15 @@ export const isScrollEnabledProperty = new Property<WebViewExtBase, boolean>({
101102
valueConverter: booleanConverter
102103
});
103104

105+
export const normalizeUrlsProperty = new Property<WebViewExtBase, boolean>({
106+
name: 'normalizeUrls',
107+
defaultValue: true,
108+
valueConverter: booleanConverter
109+
});
110+
export const normalizeUrlsOptionsProperty = new Property<WebViewExtBase, any>({
111+
name: 'normalizeUrlsOptions'
112+
});
113+
104114
export type ViewPortValue = boolean | ViewPortProperties;
105115
export const viewPortProperty = new Property<WebViewExtBase, ViewPortValue>({
106116
name: 'viewPortSize',
@@ -363,7 +373,9 @@ export class UnsupportedSDKError extends Error {
363373

364374
@CSSType('WebView')
365375
export abstract class WebViewExtBase extends ContainerView {
366-
public webConsole: boolean;
376+
public webConsoleEnabled: boolean;
377+
public normalizeUrls: boolean;
378+
public normalizeUrlsOptions: any;
367379

368380
public static readonly supportXLocalScheme: boolean;
369381

@@ -1092,15 +1104,11 @@ export abstract class WebViewExtBase extends ContainerView {
10921104
}
10931105

10941106
public normalizeURL(url: string): string {
1095-
if (!url) {
1096-
return url;
1097-
}
1098-
1099-
if (url.startsWith(this.interceptScheme)) {
1107+
if (!url || !this.normalizeUrls || url.startsWith(this.interceptScheme)) {
11001108
return url;
11011109
}
11021110

1103-
return URL.parse(url).format();
1111+
return normalizeUrl(url, this.normalizeUrlsOptions);
11041112
}
11051113

11061114
/**
@@ -1561,6 +1569,8 @@ cacheModeProperty.register(WebViewExtBase);
15611569
databaseStorageProperty.register(WebViewExtBase);
15621570
debugModeProperty.register(WebViewExtBase);
15631571
webConsoleProperty.register(WebViewExtBase);
1572+
normalizeUrlsProperty.register(WebViewExtBase);
1573+
normalizeUrlsOptionsProperty.register(WebViewExtBase);
15641574
displayZoomControlsProperty.register(WebViewExtBase);
15651575
domStorageProperty.register(WebViewExtBase);
15661576
srcProperty.register(WebViewExtBase);

0 commit comments

Comments
 (0)