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

Bug report: Register not usable for ingredient type "number" #604

Closed
fletcher2 opened this issue Jul 26, 2019 · 2 comments
Closed

Bug report: Register not usable for ingredient type "number" #604

fletcher2 opened this issue Jul 26, 2019 · 2 comments
Labels

Comments

@fletcher2
Copy link

Describe the bug
Ingredients of type number are represented by input type=number via HTMLIngredient.
That makes it impossible to use Register stored values like in the example below
The link doesnt even contain the $R0 for padding length (null in the example)
To Reproduce
Steps to reproduce the behavior or a link to the recipe / input used to cause the bug:
https://gchq.github.io/CyberChef/#recipe=Register('(%5B%5C%5Cs%5C%5CS%5D*)',true,false,false)Pad_lines('Start',null,'1')&input=%5Bobject%20Object%5D,%5Bobject%20Object%5D
Replace length with $R0
Expected behavior
The $R0 reference gets replaced by the stored value

Additional context
Add any other context about the problem here.
I dont see a better solution than replacing input type=number with type=text leading to the downside that the html5 inherent input validation has to be provided as well

@fletcher2 fletcher2 added the bug label Jul 26, 2019
@fletcher2
Copy link
Author

For me the following patches were sufficient - no validation

diff --git a/src/web/HTMLIngredient.mjs b/src/web/HTMLIngredient.mjs
index 6f3f5e66..835bcb20 100755
--- a/src/web/HTMLIngredient.mjs
+++ b/src/web/HTMLIngredient.mjs
@@ -101,14 +101,11 @@ class HTMLIngredient {
             case "number":
                 html += `<div class="form-group inline">
                     <label for="${this.id}" class="bmd-label-floating inline">${this.name}</label>
-                    <input type="number"
+                    <input type="text"
                         class="form-control arg inline"
                         id="${this.id}"
                         arg-name="${this.name}"
                         value="${this.value}"
-                        min="${this.min}"
-                        max="${this.max}"
-                        step="${this.step}"
                         ${this.disabled ? "disabled" : ""}>
                     ${this.hint ? "<span class='bmd-help'>" + this.hint + "</span>" : ""}
                 </div>`;
diff --git a/src/core/Ingredient.mjs b/src/core/Ingredient.mjs
index f74b42d6..8336bfc7 100755
--- a/src/core/Ingredient.mjs
+++ b/src/core/Ingredient.mjs
@@ -115,8 +115,11 @@ class Ingredient {
             case "number":
                 number = parseFloat(data);
                 if (isNaN(number)) {
-                    const sample = Utils.truncate(data.toString(), 10);
-                    throw "Invalid ingredient value. Not a number: " + sample;
+                    if(data.match(/^(\\*)\$R(\d{1,2})$/) === null){
+                        const sample = Utils.truncate(data.toString(), 10);
+                        throw "Invalid ingredient value. Not a number: " + sample;
+                    }
+                    return data
                 }
                 return number;
             default:

@n1474335
Copy link
Member

This is tricky. I'd really rather not change the input to a text type as that feels wrong. It'll make the min, max and step attributes much more difficult to implement. I think for the moment we'll accept this lack of functionality. I'll close this issue for now but if there are a lot of people asking for it to be addressed we can take another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants