Skip to content

Commit

Permalink
fix: invalid input with initial underscore (#1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
idoros authored Nov 4, 2024
1 parent be46b7a commit db35260
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions packages/define-remix-app/src/define-remix-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ export default function defineRemixApp({ appPath, routingPattern = 'file' }: IDe
})
.join('.');
const pageName = toCamelCase(pageFileName);
if (!pageName) {
if (!pageName && !requestedURI) {
return {
isValid: false,
errorMessage: INVALID_MSGS.emptyName,
pageModule: '',
newPageSourceCode: '',
};
} else if (!pageName[0].match(/[A-Za-z]/)) {
} else if (!(pageName[0] || requestedURI[0]).match(/[A-Za-z]/)) {
return {
isValid: false,
errorMessage: 'Page names must start with a letter of the alphabet',
errorMessage: INVALID_MSGS.initialPageLetter,
pageModule: '',
newPageSourceCode: '',
};
Expand Down
17 changes: 10 additions & 7 deletions packages/define-remix-app/test/define-remix.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1024,14 +1024,17 @@ describe('define-remix', () => {
[indexPath]: simpleLayout,
});

const { isValid, errorMessage, pageModule, newPageRoute, newPageSourceCode } =
driver.getNewPageInfo('1st-page');
const invalidCases = ['1st-page', '_about'];
for (const invalidCase of invalidCases) {
const { isValid, errorMessage, pageModule, newPageRoute, newPageSourceCode } =
driver.getNewPageInfo(invalidCase);

expect(isValid, 'isValid').to.eql(false);
expect(errorMessage, 'error message').to.eql(INVALID_MSGS.initialPageLetter);
expect(pageModule, 'page module').to.eql('');
expect(newPageSourceCode, 'newPageSourceCode').to.eql('');
expect(newPageRoute, 'newPageRoute').to.eql(undefined);
expect(isValid, `isValid ${invalidCase}`).to.eql(false);
expect(errorMessage, `error message ${invalidCase}`).to.eql(INVALID_MSGS.initialPageLetter);
expect(pageModule, `page module ${invalidCase}`).to.eql('');
expect(newPageSourceCode, `newPageSourceCode ${invalidCase}`).to.eql('');
expect(newPageRoute, `newPageRoute ${invalidCase}`).to.eql(undefined);
}
});
it('should limit route param key', async () => {
const { driver } = await getInitialManifest({
Expand Down

0 comments on commit db35260

Please sign in to comment.