Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

making blank line after header optional #264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions __tests__/chess.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,16 @@ describe("Load PGN", function() {
expect: true,
sloppy: true
},

// parse should succeed with missing blank line after headers
{pgn: [
'[Round "1"]',
'1. e4 c5 2. Nf3 d6 3. d4 cxd4',
],
fen: 'rnbqkbnr/pp2pppp/3p4/8/3pP3/5N2/PPP2PPP/RNBQKB1R w KQkq - 0 4',
expect: true,
sloppy: true
},
];

var newline_chars = ['\n', '<br />', '\r\n', 'BLAH'];
Expand Down
12 changes: 3 additions & 9 deletions chess.js
Original file line number Diff line number Diff line change
Expand Up @@ -1580,16 +1580,10 @@ var Chess = function(fen) {
? options.newline_char
: '\r?\n'

// RegExp to split header. Takes advantage of the fact that header and movetext
// will always have a blank line between them (ie, two newline_char's).
// With default newline_char, will equal: /^(\[((?:\r?\n)|.)*\])(?:\r?\n){2}/
// RegExp to split header. This assumes that the header is the initial
// set of lines which begin with [ and end with ].
var header_regex = new RegExp(
'^(\\[((?:' +
mask(newline_char) +
')|.)*\\])' +
'(?:' +
mask(newline_char) +
'){2}'
'^((?:\\[.*\\]' + mask(newline_char) + ')+)'
)

// If no header given, begin with moves.
Expand Down