gchq / gchq/CyberChef

Bug report: Race condition when the url contains input encoding that sometimes makes UI tests fail

Open
#1,773 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
35.8k
Forks
4.1k
Avg merge
2d 26m
Merged PRs (30d)
33

Description

(I'm not sure about this analysis and how that should be fixed hence I submit this as an issue not a PR)

In the `loadUriParams` function we see the following code:
```javascript
// Input Character Encoding
// Must be set before the input is loaded
if (this.uriParams.ienc) {
this.manager.input.chrEncChange(parseInt(this.uriParams.ienc, 10), true);
}
```

The `chrEncChange` function in turn calls `inputChange`:
```javascript
chrEncChange(chrEncVal, manual=false) {
if (typeof chrEncVal !== "number") return;
this.inputChrEnc = chrEncVal;
this.encodingState = manual ? 2 : this.encodingState;
this.inputChange();
}
```

Note that at the time this is called, the input is empty.. (edit: or not changed)
Then inside `inputChange` we have a debounce call which actually works like setTimeout. Since the doc is empty, this function will be called after 20ms and will call `updateInputValue` with the current value of the input:
```javascript
const inputLength = this.inputEditorView.state.doc.length;
let delay;
if (inputLength < 10000) delay = 20;
else if (inputLength < 100000) delay = 50;
else if (inputLength < 1000000) delay = 200;
else delay = 500;

// ...

debounce(function(e) {
// ...
const value = this.getInput();
this.updateInputValue(activeTab, value);
```

And here's the problem... by the time this is called, the input might not yet be ready, hence we overwrite the input value with the previous one / empty string.
This makes the "Loading from URL" test fail on my machine, although not always. It's easier to reproduce if the "delay" is artificially lowered to 1.

Would it make sense to create a separate parameter for chrEncChange whether to skip calling inputChange?

Contributor guide

Open the contributing guide

Research direction

Start with loadUriParams, chrEncChange, inputChange, and updateInputValue to trace the debounced update during URL loading. Reproduce the intermittent failure in the "Loading from URL" test, especially with a shorter delay, and determine how to prevent a delayed update from overwriting the loaded input. Done means the test is reliable and URL input is preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.