Skip to content
Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ All notable changes to ModShift are documented here. The format follows
### Fixed

- `migrate` (and the config and web UI) now reject a loader version that is not a version, such
as a `<version>` placeholder copied from an example, instead of writing an invalid pack.
as a `<version>` or `X.Y.Z` placeholder copied from an example (a version must contain a
digit), instead of writing an invalid pack.
- Unrelated alternatives: a popular mod sharing only a broad category (e.g. Xaero's Minimap for
CIT Resewn) is no longer suggested; a candidate needs a similar name or two shared keywords
(one generic word such as "screen" is not enough).
Expand Down
7 changes: 4 additions & 3 deletions src/loaders/loaderVersion.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Format d'une version de loader écrite dans un .mrpack (ex. 0.16.5, 21.1.77, 47.3.0,
// 0.27.1-beta.1). Refuse ce qui n'est clairement pas une version (ex. « <version> » recopié
// d'un exemple), sans prétendre vérifier qu'elle existe.
// 0.27.1-beta.1). Refuse ce qui n'est clairement pas une version (ex. « <version> » ou « X.Y.Z »
// recopiés d'un exemple : toute vraie version contient un chiffre), sans prétendre vérifier
// qu'elle existe.
const LOADER_VERSION_PATTERN = /^[0-9A-Za-z][0-9A-Za-z.+_-]{0,63}$/;

export function isValidLoaderVersion(value: string): boolean {
return LOADER_VERSION_PATTERN.test(value);
return LOADER_VERSION_PATTERN.test(value) && /[0-9]/.test(value);
}

export function invalidLoaderVersionMessage(value: string): string {
Expand Down
15 changes: 11 additions & 4 deletions test/loaders/loaderVersion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ describe('loader version format', () => {
(version) => expect(isValidLoaderVersion(version)).toBe(true),
);

it.each(['<version>', '', ' 0.16.5', '0.16 .5', '-0.16.5', 'x'.repeat(65), '0.16.5;rm'])(
'rejects %j',
(version) => expect(isValidLoaderVersion(version)).toBe(false),
);
it.each([
'<version>',
'X.Y.Z',
'latest',
'',
' 0.16.5',
'0.16 .5',
'-0.16.5',
'x'.repeat(65),
'0.16.5;rm',
])('rejects %j', (version) => expect(isValidLoaderVersion(version)).toBe(false));

it('rejects an invalid target.loaderVersion in the config', () => {
expect(() => validateConfig({ target: { loaderVersion: '<version>' } }, 'c.json')).toThrow(
Expand Down
Loading