Skip to content

Commit 58a6ed9

Browse files
Copilotalexr00
andcommitted
Add query string trimming to fix trailing whitespace issue
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent a8f78cf commit 58a6ed9

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/issues/stateManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ export class StateManager {
329329
items = this.setIssues(
330330
folderManager,
331331
// Do not resolve pull request defaults as they will get resolved in the query later per repository
332-
variableSubstitution(query.query, undefined, undefined, user),
332+
variableSubstitution(query.query, undefined, undefined, user).trim(),
333333
).then(issues => ({ groupBy: query.groupBy ?? [], issues }));
334334

335335
if (items) {

src/test/issues/stateManager.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,49 @@ describe('StateManager branch behavior with useBranchForIssues setting', functio
124124
vscode.workspace.getConfiguration = originalGetConfiguration;
125125
}
126126
});
127+
128+
it('should trim whitespace from query strings', async function () {
129+
const mockUri = vscode.Uri.parse('file:///test');
130+
const mockFolderManager = {
131+
repository: { rootUri: mockUri, state: { HEAD: { commit: 'abc123' } } },
132+
getIssues: async (query: string) => {
133+
// Verify that the query doesn't have trailing whitespace
134+
assert.strictEqual(query, query.trim(), 'Query should be trimmed');
135+
assert.strictEqual(query.endsWith(' '), false, 'Query should not end with whitespace');
136+
return { items: [], hasMorePages: false, hasUnsearchedRepositories: false, totalCount: 0 };
137+
},
138+
getMaxIssue: async () => 0,
139+
};
140+
141+
// Mock workspace configuration with query that has trailing space
142+
const originalGetConfiguration = vscode.workspace.getConfiguration;
143+
vscode.workspace.getConfiguration = (section?: string) => {
144+
if (section === ISSUES_SETTINGS_NAMESPACE) {
145+
return {
146+
get: (key: string, defaultValue?: any) => {
147+
if (key === 'queries') {
148+
return [{ label: 'Test', query: 'is:open assignee:@me repo:owner/repo ', groupBy: [] }];
149+
}
150+
return defaultValue;
151+
},
152+
} as any;
153+
}
154+
return originalGetConfiguration(section);
155+
};
156+
157+
try {
158+
// Initialize the state manager with a query that has trailing space
159+
const stateManager = new StateManager(undefined as any, {
160+
folderManagers: [mockFolderManager],
161+
credentialStore: { isAnyAuthenticated: () => true, getCurrentUser: async () => ({ login: 'testuser' }) },
162+
} as any, mockContext);
163+
164+
// Manually trigger the setIssueData flow
165+
await (stateManager as any).setIssueData(mockFolderManager);
166+
167+
// If we get here without assertion failures in getIssues, the test passed
168+
} finally {
169+
vscode.workspace.getConfiguration = originalGetConfiguration;
170+
}
171+
});
127172
});

0 commit comments

Comments
 (0)