Skip to content

Commit 00c0871

Browse files
committed
arduino#919: Fixed empty string to URLs conversion
Closes arduino#919. Signed-off-by: Akos Kitta <[email protected]>
1 parent f36df02 commit 00c0871

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

arduino-ide-extension/src/browser/dialogs/settings/settings-component.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { FileDialogService } from '@theia/filesystem/lib/browser/file-dialog/fil
1010
import { DisposableCollection } from '@theia/core/lib/common/disposable';
1111
import {
1212
CompilerWarningLiterals,
13+
Config,
1314
Network,
1415
ProxySettings,
1516
} from '../../../common/protocol';
@@ -496,7 +497,7 @@ export class SettingsComponent extends React.Component<
496497
event: React.ChangeEvent<HTMLInputElement>
497498
): void => {
498499
this.setState({
499-
additionalUrls: event.target.value.split(',').map((url) => url.trim()),
500+
additionalUrls: Config.parseAdditionalUrls(event.target.value, ','),
500501
});
501502
};
502503

arduino-ide-extension/src/browser/dialogs/settings/settings-dialog.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { FileDialogService } from '@theia/filesystem/lib/browser/file-dialog/fil
1111
import { nls } from '@theia/core/lib/common';
1212
import { SettingsComponent } from './settings-component';
1313
import { AsyncLocalizationProvider } from '@theia/core/lib/common/i18n/localization';
14+
import { Config } from '../../../common/protocol';
1415

1516
@injectable()
1617
export class SettingsWidget extends ReactWidget {
@@ -96,7 +97,7 @@ export class SettingsDialog extends AbstractDialog<Promise<Settings>> {
9697
this.update();
9798
}
9899

99-
protected onUpdateRequest(msg: Message) {
100+
protected onUpdateRequest(msg: Message): void {
100101
super.onUpdateRequest(msg);
101102
this.widget.update();
102103
}
@@ -105,7 +106,7 @@ export class SettingsDialog extends AbstractDialog<Promise<Settings>> {
105106
super.onActivateRequest(msg);
106107

107108
// calling settingsService.reset() in order to reload the settings from the preferenceService
108-
// and update the UI including changes triggerd from the command palette
109+
// and update the UI including changes triggered from the command palette
109110
this.settingsService.reset();
110111

111112
this.widget.activate();
@@ -168,10 +169,7 @@ export class AdditionalUrlsDialog extends AbstractDialog<string[]> {
168169
}
169170

170171
get value(): string[] {
171-
return this.textArea.value
172-
.split('\n')
173-
.map((url) => url.trim())
174-
.filter((url) => !!url);
172+
return Config.parseAdditionalUrls(this.textArea.value, 'newline');
175173
}
176174

177175
protected onAfterAttach(message: Message): void {

arduino-ide-extension/src/common/protocol/config-service.ts

+10
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,14 @@ export namespace Config {
140140
Network.sameAs(left.network, right.network)
141141
);
142142
}
143+
export function parseAdditionalUrls(
144+
value: string,
145+
delimiter: ',' | 'newline'
146+
): string[] {
147+
return value
148+
.trim()
149+
.split(delimiter === ',' ? delimiter : /\r?\n/)
150+
.map((url) => url.trim())
151+
.filter((url) => !!url);
152+
}
143153
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { expect } from 'chai';
2+
import { Config } from '../../common/protocol';
3+
4+
describe('config-service', () => {
5+
describe('parseAdditionalUrls', () => {
6+
it('should parse an empty string as an empty array', () => {
7+
expect(Config.parseAdditionalUrls('', ',')).to.be.empty;
8+
});
9+
it('should parse a blank string as an empty array', () => {
10+
expect(Config.parseAdditionalUrls(' ', ',')).to.be.empty;
11+
});
12+
it('should parse urls with commas', () => {
13+
expect(
14+
Config.parseAdditionalUrls(' ,a , b , c, ', ',')
15+
).to.be.deep.equal(['a', 'b', 'c']);
16+
});
17+
it("should parse urls with both '\\n' and '\\r\\n' line endings", () => {
18+
expect(
19+
Config.parseAdditionalUrls(
20+
'a ' + '\r\n' + ' b ' + '\n' + ' c ' + '\r\n' + ' ' + '\n' + '',
21+
'newline'
22+
)
23+
).to.be.deep.equal(['a', 'b', 'c']);
24+
});
25+
});
26+
});

0 commit comments

Comments
 (0)