Fix bug scripts in Mitmweb (#6668)

#### Description

This PR should fix issue: #6002 

#### Checklist

 - [x] I have updated tests where applicable.
 - [ ] I have added an entry to the CHANGELOG.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Matteo Luppi 2024-02-20 09:59:35 +01:00 committed by GitHub
parent 3ba4b65ecd
commit 240a286b2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 4 deletions

View file

@ -97,6 +97,6 @@ describe("StringOption Component", () => {
it("should handle onChange", () => {
let mockEvent = { target: { value: "a\nb\nc\n" } };
tree.props.onChange(mockEvent);
expect(onChangeFn).toBeCalledWith(["a", "b", "c", ""]);
expect(onChangeFn).toBeCalledWith(["a", "b", "c"]);
});
});

View file

@ -99,11 +99,26 @@ StringSequenceOption.propTypes = {
function StringSequenceOption({ value, onChange, ...props }) {
const height = Math.max(value.length, 1);
const [textAreaValue, setTextAreaValue] = React.useState(value.join("\n"));
const handleChange = (e) => {
const newValue = e.target.value;
setTextAreaValue(newValue); //save in the state the current input value
onChange(
//we send to the backend only the strings that are not empty
newValue
.split("\n")
.map((line) => line.trim())
.filter((line) => line !== "")
);
};
return (
<textarea
rows={height}
value={value.join("\n")}
onChange={(e) => onChange(e.target.value.split("\n"))}
value={textAreaValue}
onChange={handleChange}
{...props}
/>
);

View file

@ -34,7 +34,9 @@ export default function reducer(state = defaultState, action): OptionsState {
export async function pureSendUpdate(option: Option, value, dispatch) {
try {
const response = await fetchApi.put("/options", { [option]: value });
const response = await fetchApi.put("/options", {
[option]: value,
});
if (response.status === 200) {
dispatch(optionsEditorActions.updateSuccess(option));
} else {