diff --git a/__tests__/chess.test.js b/__tests__/chess.test.js index 02947988..f201013a 100644 --- a/__tests__/chess.test.js +++ b/__tests__/chess.test.js @@ -1371,6 +1371,10 @@ describe('Validate FEN', () => { fen: 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 x', error_number: 2, }, + { + fen: 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 ', + error_number: 2, + }, { fen: 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 0', error_number: 2, diff --git a/chess.js b/chess.js index caf12efb..ecd83b79 100644 --- a/chess.js +++ b/chess.js @@ -432,12 +432,12 @@ export const Chess = function (fen) { } /* 2nd criterion: move number field is a integer value > 0? */ - if (isNaN(tokens[5]) || parseInt(tokens[5], 10) <= 0) { + if (isNaN(parseInt(tokens[5])) || parseInt(tokens[5], 10) <= 0) { return { valid: false, error_number: 2, error: errors[2] } } /* 3rd criterion: half move counter is an integer >= 0? */ - if (isNaN(tokens[4]) || parseInt(tokens[4], 10) < 0) { + if (isNaN(parseInt(tokens[4])) || parseInt(tokens[4], 10) < 0) { return { valid: false, error_number: 3, error: errors[3] } }