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

fix: sonar issues in regex expressions #3979

Merged
merged 4 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions src/util/dynamicConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ const get = require('get-value');
const unset = require('unset-value');

function getDynamicConfigValue(event, value) {
// this regex checks for pattern "only spaces {{ path || defaultvalue }} only spaces" .
// " {{message.traits.key || \"email\" }} "
// " {{ message.traits.key || 1233 }} "
// Refined regex to ensure safety and avoid super-linear runtime
const defFormat =
/^\s*{{\s*(?<path>[A-Z_a-z]\w*(?:\.[A-Z_a-z]\w*)+)\s*\|\|\s*(?<defaultVal>.*)\s*}}\s*$/;
/^\s*{{\s*(?<path>[A-Z_a-z]\w*(?:\.[A-Z_a-z]\w*)*)\s*\|\|\s*(?<defaultVal>[^{|}]+)\s*}}\s*$/;

const matResult = value.match(defFormat);
if (matResult) {
// Support "event.<obj1>.<key>" alias for "message.<obj1>.<key>"
Expand All @@ -21,6 +20,7 @@ function getDynamicConfigValue(event, value) {
}
return value;
}

/** var format2 = /<some other regex>/;
matResult = value.match(format2);
if (matResult) {
Expand Down
2 changes: 1 addition & 1 deletion src/v0/destinations/af/deleteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const userDeletionHandler = async (userAttributes, config) => {
if (config.statusCallbackUrls) {
const statusCallbackUrlsArray = config.statusCallbackUrls.split(',');
const filteredStatusCallbackUrlsArray = statusCallbackUrlsArray.filter((statusCallbackUrl) => {
const URLRegex = /^(https?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w!#$&'()*+,/:;=?@[\]~-]+$/;
const URLRegex = /^(https?:\/\/)?[\w.-]+(\.[A-Za-z]{2,})+([#/?]\S*)?$/;
koladilip marked this conversation as resolved.
Show resolved Hide resolved
return statusCallbackUrl.match(URLRegex);
});
if (filteredStatusCallbackUrlsArray.length > 3) {
Expand Down
2 changes: 1 addition & 1 deletion src/v0/destinations/airship/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const identifyResponseBuilder = (message, { Config }) => {
// attribute
if (typeof traits[key] !== 'boolean') {
const attribute = { action: 'set' };
const keyMapped = RESERVED_TRAITS_MAPPING[key.toLowerCase()];
const keyMapped = RESERVED_TRAITS_MAPPING[key] || RESERVED_TRAITS_MAPPING[key.toLowerCase()];
if (keyMapped) {
attribute.key = keyMapped;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/v0/destinations/clickup/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const validateEmail = (email) => {
* @param {*} url
*/
const validateUrl = (url) => {
const regex = /^(https?:\/\/)[\w.-]+(?:\.[\w.-]+)+[\w!#$&'()*+,/:;=?@[\]~-]+$/;
const regex = /^https?:\/\/[\w.-]+(\.[A-Za-z]{2,})+([#/?]\S*)?$/;
koladilip marked this conversation as resolved.
Show resolved Hide resolved
if (!regex.test(url)) {
throw new InstrumentationError('The provided url is invalid');
}
Expand Down
Loading