Skip to content

Commit

Permalink
Merge pull request #125 from koblas/fix_ec_ci
Browse files Browse the repository at this point in the history
fix: ec/ci prefix validation
  • Loading branch information
koblas authored Jan 14, 2025
2 parents 6a84d84 + edcbc61 commit fbf9317
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
lib
coverage
12 changes: 11 additions & 1 deletion src/ec/ci.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { validate, format } from './ci';
import { InvalidLength, InvalidChecksum } from '../exceptions';
import {
InvalidLength,
InvalidChecksum,
InvalidComponent,
} from '../exceptions';

describe('ec/ci', () => {
it('format:1714307103', () => {
Expand All @@ -25,4 +29,10 @@ describe('ec/ci', () => {

expect(result.error).toBeInstanceOf(InvalidChecksum);
});

it('validate:2714307104', () => {
const result = validate('2714307104');

expect(result.error).toBeInstanceOf(InvalidComponent);
});
});
2 changes: 1 addition & 1 deletion src/ec/ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function clean(input: string): ReturnType<typeof strings.cleanUnicode> {

export function validPrefix(value: string): boolean {
const prefix = parseInt(value.substr(0, 2), 10);
if (prefix === 0 || prefix > 24 || prefix === 30 || prefix === 50) {
if ((prefix < 1 || prefix > 24) && !(prefix === 30 || prefix === 50)) {
// Invalid province
return false;
}
Expand Down

0 comments on commit fbf9317

Please sign in to comment.