diff --git a/cocoscreator_projects/scripts/test/ui-frames.test.mjs b/cocoscreator_projects/scripts/test/ui-frames.test.mjs index 515862d..fd662d2 100644 --- a/cocoscreator_projects/scripts/test/ui-frames.test.mjs +++ b/cocoscreator_projects/scripts/test/ui-frames.test.mjs @@ -73,10 +73,17 @@ test('frameFileName 单帧图原样返回', () => { test('frameFileName undefined 作为 frameIndex 抛 RangeError', () => { assert.throws(() => frameFileName('00014.png', undefined, 12), RangeError); + assert.throws(() => frameFileName('00014.png', undefined, 12), /00014\.png/); }); test('frameFileName NaN 作为 frameIndex 抛 RangeError', () => { assert.throws(() => frameFileName('00014.png', NaN, 12), RangeError); + assert.throws(() => frameFileName('00014.png', NaN, 12), /00014\.png/); +}); + +test('frameFileName 越界抛 RangeError 且带图名', () => { + assert.throws(() => frameFileName('00014.png', 13, 12), RangeError); + assert.throws(() => frameFileName('00014.png', 13, 12), /00014\.png/); }); test('frameNames 返回全部帧,下标 0 对应帧 1', () => { diff --git a/cocoscreator_projects/scripts/ui-migration/frames.mjs b/cocoscreator_projects/scripts/ui-migration/frames.mjs index acf0a84..ffc4e12 100644 --- a/cocoscreator_projects/scripts/ui-migration/frames.mjs +++ b/cocoscreator_projects/scripts/ui-migration/frames.mjs @@ -29,9 +29,9 @@ export function padWidth(frameCount) { export function frameFileName(bmp, frameIndex, frameCount) { if (frameCount <= 1) return bmp; const normalized = frameIndex === 0 ? 1 : frameIndex; - if (!Number.isInteger(normalized) || normalized <= 0) { + if (!Number.isInteger(normalized) || normalized <= 0 || normalized > frameCount) { throw new RangeError( - `帧号非法: ${bmp} frameIndex=${frameIndex}(有效范围 >= 1,0 视同 1)`, + `帧号非法或越界: ${bmp} frameIndex=${frameIndex}(有效范围 1..${frameCount},0 视同 1)`, ); } const base = bmp.replace(/\.png$/i, '');