Skip to content

Commit

Permalink
try to fix deep linking to make sure only supported pattern is opened in
Browse files Browse the repository at this point in the history
app
  • Loading branch information
kamalkishor1991 committed Nov 1, 2024
1 parent e74f7e9 commit 42bb801
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions ApplicationRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,33 @@ export default function App() {
const urlParts = url.split('?');
const path = urlParts[0].split('/');
const colorsPart = path[path.length - 1];

// Split the colors part by `-` to get the color codes
const colors = colorsPart.split('-');

// Parse the query parameters
const queryParamsString = urlParts[1] || '';
const queryParams = {};
queryParamsString.split('&').forEach((param) => {
const [key, value] = param.split('=');
queryParams[key] = decodeURIComponent(value);
});

const suggestedName = queryParams['name'];
navigationRef.navigate('SavePalette', {
colors: colors.map((color) => {
return { color: '#' + color };
}),
suggestedName: suggestedName
});

// Validate if colorsPart matches a hex color pattern (e.g., FFFFFF-123456)
const isValidPattern = /^([0-9A-Fa-f]{6})(-[0-9A-Fa-f]{6})*$/.test(colorsPart);

if (isValidPattern) {
// Split the colors part by `-` to get the color codes
const colors = colorsPart.split('-');

// Parse the query parameters
const queryParamsString = urlParts[1] || '';
const queryParams = {};
queryParamsString.split('&').forEach((param) => {
const [key, value] = param.split('=');
queryParams[key] = decodeURIComponent(value);
});

const suggestedName = queryParams['name'];
navigationRef.navigate('SavePalette', {
colors: colors.map((color) => {
return { color: '#' + color };
}),
suggestedName: suggestedName,
});
} else {
// Open URL in the default browser if pattern does not match
Linking.openURL(url);
}
} catch (error) {
notifyMessage('Error parsing url: ' + error.message);
navigationRef.navigate(ROUTE_NAMES.HOME);
Expand Down

0 comments on commit 42bb801

Please sign in to comment.