Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] ranges: getRangeFromSheetXC with invalid sheetId #4275

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plugins/core/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export class RangeAdapter implements CommandHandler<CoreCommand> {
* @param sheetXC the string description of a range, in the form SheetName!XC:XC
*/
getRangeFromSheetXC(defaultSheetId: UID, sheetXC: string): RangeImpl {
if (!rangeReference.test(sheetXC)) {
if (!rangeReference.test(sheetXC) || !this.getters.tryGetSheet(defaultSheetId)) {
return new RangeImpl(
{
sheetId: "",
Expand Down
22 changes: 22 additions & 0 deletions tests/plugins/range.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,28 @@ describe("range plugin", () => {
deleteSheet(m, "s1");
expect(m.getters.getRangeString(range)).toBe(INCORRECT_RANGE_STRING);
});

test("getRangeFromSheetXC on invalid sheet", () => {
let getRange = () => m.getters.getRangeFromSheetXC("NotASheet", "A1");
expect(getRange).not.toThrow();
expect(getRange().invalidXc).toBe("A1");

getRange = () => m.getters.getRangeFromSheetXC("NotASheet", "A:A");
expect(getRange).not.toThrow();
expect(getRange().invalidXc).toBe("A:A");

getRange = () => m.getters.getRangeFromSheetXC("NotASheet", "Sheet1!A1");
expect(getRange).not.toThrow();
expect(getRange().invalidXc).toBe("Sheet1!A1");

getRange = () => m.getters.getRangeFromSheetXC("", "Sheet1!A:A");
expect(getRange).not.toThrow();
expect(getRange().invalidXc).toBe("Sheet1!A:A");

getRange = () => m.getters.getRangeFromSheetXC("", "A1:A2");
expect(getRange).not.toThrow();
expect(getRange().invalidXc).toBe("A1:A2");
});
});

describe("Helpers", () => {
Expand Down