Jump to conversation
Unresolved conversations (1)
@per1234 per1234 Sep 7, 2022
There is a regression here for a use case that is not explicitly supported by the specification, but is supported by the Arduino IDE 1.x Serial Plotter and previous implementation of this project. That use case is the combination of a trailing delimiter and `\r\n` separator. For example: ```cpp void setup() { Serial.begin(9600); } void loop() { for (byte value = 0; value < 4; value++) { for (byte variableOffset = 0; variableOffset < 3; variableOffset++) { Serial.print(value + variableOffset); Serial.print('\t'); } Serial.println(); } delay(100); } ``` You can see how code that generates data via a `for` loop favors a trailing delimiter, and of course `Serial.println();` is a convenient way to produce a separator. Previously, that sketch produced 3 variables as expected: Arduino IDE 1.8.19: ![image](https://user-images.githubusercontent.com/8572152/188775082-ead87519-2cf0-420f-9d89-fbcfd72632d7.png) arduino-serial-plotter-webapp@https://github.com/arduino/arduino-serial-plotter-webapp/commit/eac6d39f3f5156390bc4f9e09cafcccc121248c9 / arduino-serial-plotter-webapp@0.1.0 / Arduino IDE 2.0.0-rc9.3: ![image](https://user-images.githubusercontent.com/8572152/188775235-7caef3e9-83bd-413c-9d26-0d59238641b0.png) After the change made here, it produces 4 variables: ![image](https://user-images.githubusercontent.com/8572152/188774020-0632851e-6e7a-4085-988f-96fcd3140a43.png) The problem is the `\r` in the `\r\n` separator produced by `Serial.println();` is being treated as a separate value. Previously, that `\r` was consumed by `message.split(/\s/);` (because [it matches `/\s/`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes#types)).
src/msgAggregatorWorker.ts
per1234 nmzaheer
Per Tillisch and Zaheer
Resolved conversations (6)
@per1234 per1234 Sep 12, 2022
```suggestion "version": "0.0.18", ``` This is wrong (it was a mistake made some time ago when a release was done incorrectly), but it is unrelated to the purpose of this pull request so I think it is better to leave it as is. It will be resolved by the next release of the project.
Outdated
package-lock.json
@per1234 per1234 Sep 11, 2022
```suggestion ``` Remove trailing whitespace.
Outdated
src/msgAggregatorWorker.ts
@per1234 per1234 Sep 11, 2022
```suggestion .filter((message) => !separatorRegex.test(message)) ``` Fix indentation
Outdated
src/msgAggregatorWorker.ts
@per1234 per1234 Sep 11, 2022
```suggestion if (separatorMatch && separatorMatch.index > -1) { ``` Fix indentation (this project uses spaces, not tabs)
Outdated
src/msgAggregatorWorker.ts
@per1234 per1234 Sep 7, 2022
```suggestion // otherwise they are unlabeled ```
Outdated
src/msgAggregatorWorker.ts
nmzaheer
Zaheer
@per1234 per1234 Sep 7, 2022
```suggestion var delimiterRegex = new RegExp(delimiter, "g"); ``` The capture group syntax caused the separators to be included in the `split()` output, resulting in unexpected additional variables: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split#splitting_with_a_regexp_to_include_parts_of_the_separator_in_the_result >If `separator` is a regular expression that contains capturing parentheses `(` `)`, matched results are included in the array. For example, this sketch: ```cpp void setup() { Serial.begin(9600); } void loop() { for (byte value = 0; value < 4; value++) { for (byte variableOffset = 0; variableOffset < 3; variableOffset++) { Serial.print(value + variableOffset); Serial.print('\t'); } Serial.print('\n'); } delay(100); } ``` Produced this chart: ![image](https://user-images.githubusercontent.com/8572152/188767061-4aa36317-1370-4ff5-b9c2-09a306e32e36.png) (Note that the legend indicates 6 variables even though the sketch only contains 3)
Outdated
src/msgAggregatorWorker.ts