Skip to content
Snippets Groups Projects
Unverified Commit d33fa86a authored by Alexander Polyankin's avatar Alexander Polyankin Committed by GitHub
Browse files

Fix pasting non-numeric values into numeric filters (#22453)

parent d5714811
No related branches found
No related tags found
No related merge requests found
......@@ -481,8 +481,9 @@ export class FieldValuesWidget extends Component {
}
// if the field is numeric we need to parse the string into an integer
if (fields[0].isNumeric()) {
if (/^-?\d+(\.\d+)?$/.test(v)) {
return parseFloat(v);
const n = Number.parseFloat(v);
if (Number.isFinite(n)) {
return n;
} else {
return null;
}
......
......@@ -300,12 +300,8 @@ export default class TokenField extends Component {
if (this.props.parseFreeformValue) {
e.preventDefault();
const string = e.clipboardData.getData("Text");
const values = this.props.multi
? string
.split(/\n|,/g)
.map(this.props.parseFreeformValue)
.filter(s => s)
: [string];
const lines = this.props.multi ? string.split(/\n|,/g) : [string];
const values = lines.map(this.props.parseFreeformValue).filter(s => s);
if (values.length > 0) {
this.addValue(values);
}
......
import { openOrdersTable, restore } from "__support__/e2e/cypress";
describe("issue 9339", () => {
beforeEach(() => {
restore();
cy.signInAsAdmin();
});
it("should not paste non-numeric values into single-value numeric filters (metabase#9339)", () => {
openOrdersTable();
cy.findByText("Total").click();
cy.findByText("Filter by this column").click();
cy.findByText("Equal to").click();
cy.findByText("Greater than").click();
paste(cy.findByPlaceholderText("Enter a number"), "9339,1234");
cy.findByText("9,339").should("be.visible");
cy.findByText("1,234").should("not.exist");
cy.button("Add filter").should("be.enabled");
});
});
const paste = (selection, text) => {
selection.trigger("paste", { clipboardData: { getData: () => text } });
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment