Skip to content
Open
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
13 changes: 13 additions & 0 deletions src/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,16 @@ describe('create(filename, options)', function () {
});
});
});

describe('create() regex state bug', function () {
it('should still throw on second call with non-ISO-8859-1 fallback', function () {
assert.throws(
create.bind(null, 'file.pdf', { fallback: '€ rates.pdf' }),
/fallback.*iso-8859-1/i,
);
assert.throws(
create.bind(null, 'file.pdf', { fallback: '€' }),
/fallback.*iso-8859-1/i,
);
});
});
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,11 @@ function createparams(
throw new TypeError('fallback must be a string or boolean');
}

if (typeof fallback === 'string' && NON_LATIN1_REGEXP.test(fallback)) {
throw new TypeError('fallback must be ISO-8859-1 string');
if (typeof fallback === 'string') {
NON_LATIN1_REGEXP.lastIndex = 0;
if (NON_LATIN1_REGEXP.test(fallback)) {
throw new TypeError('fallback must be ISO-8859-1 string');
}
}

const params: Record<string, string> = new NullObject();
Expand Down