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

From parameter option added to BYOR data convert #818

Merged
merged 14 commits into from
Dec 16, 2024
19 changes: 19 additions & 0 deletions src/utils/dataConvert.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@
return string.slice(0, -1)
}

let getParameterByName = function (name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.

Copilot Autofix AI about 1 month ago

To fix the problem, we need to ensure that backslashes are also escaped in the name parameter. This can be achieved by modifying the name.replace method to include backslashes in the regular expression. We will use a regular expression with the g flag to ensure that all occurrences of special characters, including backslashes, are replaced.

Suggested changeset 1
src/utils/dataConvert.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/utils/dataConvert.js b/src/utils/dataConvert.js
--- a/src/utils/dataConvert.js
+++ b/src/utils/dataConvert.js
@@ -76,3 +76,3 @@
         if (!url) url = window.location.href;
-        name = name.replace(/[\[\]]/g, '\\$&');
+        name = name.replace(/([[\]\\])/g, '\\$&');
         var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
EOF
@@ -76,3 +76,3 @@
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
name = name.replace(/([[\]\\])/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

let applyConvert = function (d, CONVERT, PHENOTYPE_MAP) {
let tempObj = {};

Expand All @@ -80,6 +90,15 @@
let cType = c.type;

switch (cType) {
case "from parameter":
let param = c["parameter"];

tempObj[c["field name"]] = getParameterByName(param);

d[c["field name"]] = tempObj[c["field name"]];

break;

case "sub to top":

let subList = d;
Expand Down Expand Up @@ -197,7 +216,7 @@
calcString += eValue;
});

tempObj[c["field name"]] = eval(calcString);

Check failure

Code scanning / CodeQL

Code injection Critical

This code execution depends on a
user-provided value
.


if ((!!c['min number'] || c['min number'] === 0) && tempObj[c["field name"]] < c['min number']) {
Expand Down
Loading