Compare commits

...

2 Commits

Author SHA1 Message Date
Satyajit Sahoo
bb294b16f9 chore: publish
- @react-navigation/bottom-tabs@5.11.5
 - @react-navigation/compat@5.3.13
 - @react-navigation/drawer@5.12.1
 - @react-navigation/material-bottom-tabs@5.3.13
 - @react-navigation/material-top-tabs@5.3.13
 - @react-navigation/native@5.9.2
 - @react-navigation/stack@5.14.1
2021-01-22 13:45:06 +01:00
Satyajit Sahoo
4ca2d2d22b fix: normalize prefix when parsing. fixes #9081 2021-01-22 13:43:49 +01:00
17 changed files with 424 additions and 37 deletions

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.11.5](https://github.com/react-navigation/react-navigation/compare/@react-navigation/bottom-tabs@5.11.4...@react-navigation/bottom-tabs@5.11.5) (2021-01-22)
**Note:** Version bump only for package @react-navigation/bottom-tabs
## [5.11.4](https://github.com/react-navigation/react-navigation/compare/@react-navigation/bottom-tabs@5.11.3...@react-navigation/bottom-tabs@5.11.4) (2021-01-21)

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/bottom-tabs",
"description": "Bottom tab navigator following iOS design guidelines",
"version": "5.11.4",
"version": "5.11.5",
"keywords": [
"react-native-component",
"react-component",
@@ -40,7 +40,7 @@
"react-native-iphone-x-helper": "^1.3.0"
},
"devDependencies": {
"@react-navigation/native": "^5.9.1",
"@react-navigation/native": "^5.9.2",
"@testing-library/react-native": "^7.1.0",
"@types/color": "^3.0.1",
"@types/react": "^16.9.53",

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.3.13](https://github.com/react-navigation/react-navigation/compare/@react-navigation/compat@5.3.12...@react-navigation/compat@5.3.13) (2021-01-22)
**Note:** Version bump only for package @react-navigation/compat
## [5.3.12](https://github.com/react-navigation/react-navigation/compare/@react-navigation/compat@5.3.11...@react-navigation/compat@5.3.12) (2021-01-21)
**Note:** Version bump only for package @react-navigation/compat

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/compat",
"description": "Compatibility layer to write navigator definitions in static configuration format",
"version": "5.3.12",
"version": "5.3.13",
"license": "MIT",
"repository": {
"type": "git",
@@ -31,7 +31,7 @@
"clean": "del lib"
},
"devDependencies": {
"@react-navigation/native": "^5.9.1",
"@react-navigation/native": "^5.9.2",
"@types/react": "^16.9.53",
"react": "~16.13.1",
"react-native-builder-bob": "^0.17.0",

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.12.1](https://github.com/react-navigation/react-navigation/compare/@react-navigation/drawer@5.12.0...@react-navigation/drawer@5.12.1) (2021-01-22)
**Note:** Version bump only for package @react-navigation/drawer
# [5.12.0](https://github.com/react-navigation/react-navigation/compare/@react-navigation/drawer@5.11.5...@react-navigation/drawer@5.12.0) (2021-01-21)

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/drawer",
"description": "Drawer navigator component with animated transitions and gesturess",
"version": "5.12.0",
"version": "5.12.1",
"keywords": [
"react-native-component",
"react-component",
@@ -45,7 +45,7 @@
"react-native-iphone-x-helper": "^1.3.0"
},
"devDependencies": {
"@react-navigation/native": "^5.9.1",
"@react-navigation/native": "^5.9.2",
"@testing-library/react-native": "^7.1.0",
"@types/react": "^16.9.53",
"@types/react-native": "^0.63.30",

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.3.13](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-bottom-tabs@5.3.12...@react-navigation/material-bottom-tabs@5.3.13) (2021-01-22)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
## [5.3.12](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-bottom-tabs@5.3.11...@react-navigation/material-bottom-tabs@5.3.12) (2021-01-21)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/material-bottom-tabs",
"description": "Integration for bottom navigation component from react-native-paper",
"version": "5.3.12",
"version": "5.3.13",
"keywords": [
"react-native-component",
"react-component",
@@ -41,7 +41,7 @@
"clean": "del lib"
},
"devDependencies": {
"@react-navigation/native": "^5.9.1",
"@react-navigation/native": "^5.9.2",
"@testing-library/react-native": "^7.1.0",
"@types/react": "^16.9.53",
"@types/react-native": "^0.63.30",

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.3.13](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-top-tabs@5.3.12...@react-navigation/material-top-tabs@5.3.13) (2021-01-22)
**Note:** Version bump only for package @react-navigation/material-top-tabs
## [5.3.12](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-top-tabs@5.3.11...@react-navigation/material-top-tabs@5.3.12) (2021-01-21)
**Note:** Version bump only for package @react-navigation/material-top-tabs

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/material-top-tabs",
"description": "Integration for the animated tab view component from react-native-tab-view",
"version": "5.3.12",
"version": "5.3.13",
"keywords": [
"react-native-component",
"react-component",
@@ -44,7 +44,7 @@
"color": "^3.1.3"
},
"devDependencies": {
"@react-navigation/native": "^5.9.1",
"@react-navigation/native": "^5.9.2",
"@testing-library/react-native": "^7.1.0",
"@types/react": "^16.9.53",
"@types/react-native": "^0.63.30",

View File

@@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.9.2](https://github.com/react-navigation/react-navigation/compare/@react-navigation/native@5.9.1...@react-navigation/native@5.9.2) (2021-01-22)
### Bug Fixes
* normalize prefix when parsing. fixes [#9081](https://github.com/react-navigation/react-navigation/issues/9081) ([4ca2d2d](https://github.com/react-navigation/react-navigation/commit/4ca2d2d22bc9eccf87451b15c823174d98cbd0a2))
## [5.9.1](https://github.com/react-navigation/react-navigation/compare/@react-navigation/native@5.9.0...@react-navigation/native@5.9.1) (2021-01-21)
**Note:** Version bump only for package @react-navigation/native

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/native",
"description": "React Native integration for React Navigation",
"version": "5.9.1",
"version": "5.9.2",
"keywords": [
"react-native",
"react-navigation",

View File

@@ -0,0 +1,318 @@
import extractPathFromURL from '../extractPathFromURL';
it('extracts path from URL with protocol', () => {
expect(extractPathFromURL(['scheme://'], 'scheme://some/path')).toBe(
'some/path'
);
expect(extractPathFromURL(['scheme://'], 'scheme:some/path')).toBe(
'some/path'
);
expect(extractPathFromURL(['scheme://'], 'scheme:///some/path')).toBe(
'some/path'
);
expect(extractPathFromURL(['scheme:///'], 'scheme:some/path')).toBe(
'some/path'
);
expect(extractPathFromURL(['scheme:'], 'scheme:some/path')).toBe('some/path');
expect(extractPathFromURL(['scheme:'], 'scheme://some/path')).toBe(
'some/path'
);
expect(extractPathFromURL(['scheme:'], 'scheme:///some/path')).toBe(
'some/path'
);
});
it('extracts path from URL with protocol and host', () => {
expect(
extractPathFromURL(
['scheme://example.com'],
'scheme://example.com/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(['scheme://example.com'], 'scheme:example.com/some/path')
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme://example.com'],
'scheme:///example.com/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme:///example.com'],
'scheme:example.com/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(['scheme:example.com'], 'scheme:example.com/some/path')
).toBe('/some/path');
expect(
extractPathFromURL(['scheme:example.com'], 'scheme://example.com/some/path')
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme:example.com'],
'scheme:///example.com/some/path'
)
).toBe('/some/path');
});
it('extracts path from URL with protocol and host with wildcard', () => {
expect(
extractPathFromURL(
['scheme://*.example.com'],
'scheme://test.example.com/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme://*.example.com'],
'scheme:test.example.com/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme://*.example.com'],
'scheme:///test.example.com/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme:///*.example.com'],
'scheme:test.example.com/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme:*.example.com'],
'scheme:test.example.com/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme:*.example.com'],
'scheme://test.example.com/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme:*.example.com'],
'scheme:///test.example.com/some/path'
)
).toBe('/some/path');
});
it('extracts path from URL with protocol, host and path', () => {
expect(
extractPathFromURL(
['scheme://example.com/test'],
'scheme://example.com/test/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(['scheme://example.com'], 'scheme:example.com/some/path')
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme://example.com/test'],
'scheme:///example.com/test/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme:///example.com/test'],
'scheme:example.com/test/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme:example.com/test'],
'scheme:example.com/test/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme:example.com/test'],
'scheme://example.com/test/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme:example.com/test'],
'scheme:///example.com/test/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme:example.com/test'],
'scheme:///example.com//test/some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme:example.com/test'],
'scheme:///example.com/test//some/path'
)
).toBe('/some/path');
expect(
extractPathFromURL(
['scheme:example.com/test'],
'scheme:///example.com/test/some//path'
)
).toBe('/some/path');
});
it('returns undefined for non-matching protocol', () => {
expect(extractPathFromURL(['scheme://'], 'foo://some/path')).toBe(undefined);
expect(extractPathFromURL(['scheme://'], 'foo:some/path')).toBe(undefined);
expect(extractPathFromURL(['scheme://'], 'foo:///some/path')).toBe(undefined);
expect(extractPathFromURL(['scheme:///'], 'foo:some/path')).toBe(undefined);
expect(extractPathFromURL(['scheme:'], 'foo:some/path')).toBe(undefined);
expect(extractPathFromURL(['scheme:'], 'foo://some/path')).toBe(undefined);
expect(extractPathFromURL(['scheme:'], 'foo:///some/path')).toBe(undefined);
});
it('returns undefined for non-matching path', () => {
expect(extractPathFromURL(['scheme://foo'], 'scheme://some/path')).toBe(
undefined
);
expect(extractPathFromURL(['scheme://foo'], 'scheme:some/path')).toBe(
undefined
);
expect(extractPathFromURL(['scheme://foo'], 'scheme:///some/path')).toBe(
undefined
);
expect(extractPathFromURL(['scheme:///foo'], 'scheme:some/path')).toBe(
undefined
);
expect(extractPathFromURL(['scheme:foo'], 'scheme:some/path')).toBe(
undefined
);
expect(extractPathFromURL(['scheme:foo'], 'scheme://some/path')).toBe(
undefined
);
expect(extractPathFromURL(['scheme:foo'], 'scheme:///some/path')).toBe(
undefined
);
});
it('returns undefined for non-matching host', () => {
expect(
extractPathFromURL(['scheme://example.com'], 'scheme://foo.com/some/path')
).toBe(undefined);
expect(
extractPathFromURL(['scheme://example.com'], 'scheme:foo.com/some/path')
).toBe(undefined);
expect(
extractPathFromURL(['scheme://example.com'], 'scheme:///foo.com/some/path')
).toBe(undefined);
expect(
extractPathFromURL(['scheme:///example.com'], 'scheme:foo.com/some/path')
).toBe(undefined);
expect(
extractPathFromURL(['scheme:example.com'], 'scheme:foo.com/some/path')
).toBe(undefined);
expect(
extractPathFromURL(['scheme:example.com'], 'scheme://foo.com/some/path')
).toBe(undefined);
expect(
extractPathFromURL(['scheme:example.com'], 'scheme:///foo.com/some/path')
).toBe(undefined);
});
it('returns undefined for non-matching host with wildcard', () => {
expect(
extractPathFromURL(
['scheme://*.example.com'],
'scheme://test.foo.com/some/path'
)
).toBe(undefined);
expect(
extractPathFromURL(
['scheme://*.example.com'],
'scheme:test.foo.com/some/path'
)
).toBe(undefined);
expect(
extractPathFromURL(
['scheme://*.example.com'],
'scheme:///test.foo.com/some/path'
)
).toBe(undefined);
expect(
extractPathFromURL(
['scheme:///*.example.com'],
'scheme:test.foo.com/some/path'
)
).toBe(undefined);
expect(
extractPathFromURL(
['scheme:*.example.com'],
'scheme:test.foo.com/some/path'
)
).toBe(undefined);
expect(
extractPathFromURL(
['scheme:*.example.com'],
'scheme://test.foo.com/some/path'
)
).toBe(undefined);
expect(
extractPathFromURL(
['scheme:*.example.com'],
'scheme:///test.foo.com/some/path'
)
).toBe(undefined);
});

View File

@@ -0,0 +1,26 @@
import escapeStringRegexp from 'escape-string-regexp';
export default function extractPathFromURL(prefixes: string[], url: string) {
for (const prefix of prefixes) {
const protocol = prefix.match(/^[^:]+:/)?.[0] ?? '';
const host = prefix
.replace(new RegExp(`^${escapeStringRegexp(protocol)}`), '')
.replace(/\/+/g, '/') // Replace multiple slash (//) with single ones
.replace(/^\//, ''); // Remove extra leading slash
const prefixRegex = new RegExp(
`^${escapeStringRegexp(protocol)}(/)*${host
.split('.')
.map((it) => (it === '*' ? '[^/]+' : escapeStringRegexp(it)))
.join('\\.')}`
);
const normalizedURL = url.replace(/\/+/g, '/');
if (prefixRegex.test(normalizedURL)) {
return normalizedURL.replace(prefixRegex, '');
}
}
return undefined;
}

View File

@@ -5,7 +5,7 @@ import {
getStateFromPath as getStateFromPathDefault,
NavigationContainerRef,
} from '@react-navigation/core';
import escapeStringRegexp from 'escape-string-regexp';
import extractPathFromURL from './extractPathFromURL';
import type { LinkingOptions } from './types';
type ResultState = ReturnType<typeof getStateFromPathDefault>;
@@ -80,24 +80,6 @@ export default function useLinking(
getActionFromStateRef.current = getActionFromState;
});
const extractPathFromURL = React.useCallback((url: string) => {
for (const prefix of prefixesRef.current) {
const protocol = prefix.match(/^[^:]+:\/\//)?.[0] ?? '';
const host = prefix.replace(protocol, '');
const prefixRegex = new RegExp(
`^${escapeStringRegexp(protocol)}${host
.split('.')
.map((it) => (it === '*' ? '[^/]+' : escapeStringRegexp(it)))
.join('\\.')}`
);
if (prefixRegex.test(url)) {
return url.replace(prefixRegex, '');
}
}
return undefined;
}, []);
const getInitialState = React.useCallback(() => {
let state: ResultState | undefined;
@@ -106,7 +88,9 @@ export default function useLinking(
if (url != null && typeof url !== 'string') {
return url.then((url) => {
const path = url ? extractPathFromURL(url) : null;
const path = url
? extractPathFromURL(prefixesRef.current, url)
: null;
return path
? getStateFromPathRef.current(path, configRef.current)
@@ -114,7 +98,7 @@ export default function useLinking(
});
}
const path = url ? extractPathFromURL(url) : null;
const path = url ? extractPathFromURL(prefixesRef.current, url) : null;
state = path
? getStateFromPathRef.current(path, configRef.current)
@@ -131,7 +115,7 @@ export default function useLinking(
};
return thenable as PromiseLike<ResultState | undefined>;
}, [extractPathFromURL]);
}, []);
React.useEffect(() => {
const listener = (url: string) => {
@@ -139,7 +123,7 @@ export default function useLinking(
return;
}
const path = extractPathFromURL(url);
const path = extractPathFromURL(prefixesRef.current, url);
const navigation = ref.current;
if (navigation && path) {
@@ -182,7 +166,7 @@ export default function useLinking(
};
return subscribe(listener);
}, [enabled, ref, subscribe, extractPathFromURL]);
}, [enabled, ref, subscribe]);
return {
getInitialState,

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.14.1](https://github.com/react-navigation/react-navigation/compare/@react-navigation/stack@5.14.0...@react-navigation/stack@5.14.1) (2021-01-22)
**Note:** Version bump only for package @react-navigation/stack
# [5.14.0](https://github.com/react-navigation/react-navigation/compare/@react-navigation/stack@5.13.0...@react-navigation/stack@5.14.0) (2021-01-21)

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/stack",
"description": "Stack navigator component for iOS and Android with animated transitions and gestures",
"version": "5.14.0",
"version": "5.14.1",
"keywords": [
"react-native-component",
"react-component",
@@ -45,7 +45,7 @@
},
"devDependencies": {
"@react-native-community/masked-view": "^0.1.10",
"@react-navigation/native": "^5.9.1",
"@react-navigation/native": "^5.9.2",
"@testing-library/react-native": "^7.1.0",
"@types/color": "^3.0.1",
"@types/react": "^16.9.53",