Skip to content

Commit cd6bbb1

Browse files
committed
Test special characters in PGN tag names
1 parent e88f28a commit cd6bbb1

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

chess/pgn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ def __setitem__(self, key: str, value: str) -> None:
934934
if key in TAG_ROSTER:
935935
self._tag_roster[key] = value
936936
elif not TAG_NAME_REGEX.match(key):
937-
raise ValueError(f"non-alphanumeric pgn header tag: {key!r}")
937+
raise ValueError(f"invalid pgn header tag: {key!r}")
938938
elif "\n" in value or "\r" in value:
939939
raise ValueError(f"line break in pgn header {key}: {value!r}")
940940
else:

test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,6 +2252,16 @@ def test_header_with_paren(self):
22522252
self.assertEqual(game.headers["Opening"], "St. George (Baker) defense")
22532253
self.assertEqual(game.end().board(), chess.Board("8/2p2k2/1pR3p1/1P1P4/p1P2P2/P4K2/8/5r2 w - - 7 78"))
22542254

2255+
def test_special_tag_names(self):
2256+
pgn = io.StringIO("""[BlackType: "program"]""")
2257+
game = chess.pgn.read_game(pgn)
2258+
self.assertEqual(game.headers["BlackType:"], "program")
2259+
2260+
with self.assertRaises(ValueError):
2261+
game.headers["~"] = "foo"
2262+
2263+
game.headers["Equals="] = "bar"
2264+
22552265
def test_chess960_without_fen(self):
22562266
pgn = io.StringIO(textwrap.dedent("""\
22572267
[Variant "Chess960"]

0 commit comments

Comments
 (0)