Skip to content

Commit b116a57

Browse files
TheNourhanDevtools-frontend LUCI CQ
authored andcommitted
Fix CSS property autocomplete with invalid characters
Prevent autocomplete suggestions when property names contain invalid CSS characters like quotation marks. Bug: 338536264 Change-Id: I72f2c473520c34925cabcdb1c0ab71b01527c2fa Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7137858 Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org> Reviewed-by: Samiya Caur <samiyac@chromium.org>
1 parent af9f1fe commit b116a57

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

front_end/panels/elements/StylesSidebarPane.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,37 @@ describe('StylesSidebarPane', () => {
823823
assert.strictEqual(completions?.[1].text, 'overflow-wrap');
824824
assert.strictEqual(completions?.[1].subtitle, '= word-wrap');
825825
});
826+
827+
it('returns no completions when property name contains invalid characters', async () => {
828+
const attachedElement = document.createElement('div');
829+
renderElementIntoDOM(attachedElement);
830+
const cssPropertyPrompt = new CSSPropertyPrompt(mockTreeItem, true);
831+
832+
cssPropertyPrompt.attachAndStartEditing(attachedElement, noop);
833+
const suggestBox = cssPropertyPrompt.suggestBoxForTest();
834+
assert.exists(suggestBox);
835+
const spyObj = sinon.spy(suggestBox);
836+
837+
cssPropertyPrompt.setText('height"');
838+
await cssPropertyPrompt.complete(true);
839+
840+
sinon.assert.notCalled(spyObj.updateSuggestions);
841+
});
842+
843+
it('allows completions for valid property names', async () => {
844+
const attachedElement = document.createElement('div');
845+
renderElementIntoDOM(attachedElement);
846+
const cssPropertyPrompt = new CSSPropertyPrompt(mockTreeItem, true);
847+
848+
cssPropertyPrompt.attachAndStartEditing(attachedElement, noop);
849+
const spyObj = sinon.spy(cssPropertyPrompt.suggestBoxForTest());
850+
cssPropertyPrompt.setText('backgrou');
851+
await cssPropertyPrompt.complete(true);
852+
853+
assert.isTrue(spyObj?.updateSuggestions.called);
854+
const completions = spyObj?.updateSuggestions.firstCall.args[1];
855+
assert.isAbove(completions.length, 0);
856+
});
826857
});
827858
});
828859
});

front_end/panels/elements/StylesSidebarPane.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,13 @@ export class CSSPropertyPrompt extends UI.TextPrompt.TextPrompt {
18691869
Promise<UI.SuggestBox.Suggestions> {
18701870
const lowerQuery = query.toLowerCase();
18711871
const editingVariable = !this.isEditingName && expression.trim().endsWith('var(');
1872+
if (this.isEditingName && expression) {
1873+
const invalidCharsRegex = /["':;,\s()]/;
1874+
if (invalidCharsRegex.test(expression)) {
1875+
return await Promise.resolve([]);
1876+
}
1877+
}
1878+
18721879
if (!query && !force && !editingVariable && (this.isEditingName || expression)) {
18731880
return await Promise.resolve([]);
18741881
}

0 commit comments

Comments
 (0)