[gnome-chess] Fix bad pgn load behaviour
- From: Sahil Sareen <ssareen src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess] Fix bad pgn load behaviour
- Date: Sun, 29 Mar 2015 15:22:37 +0000 (UTC)
commit 0e9eaa8547d49cad65cde482334ef1e8dd4f3cab
Author: Sahil Sareen <sahil sareen hotmail com>
Date: Sun Mar 29 20:44:53 2015 +0530
Fix bad pgn load behaviour
Handle invalid fields in PGN properly.
lib/chess-pgn.vala | 35 +++++++++++++++++++++++++++++++++--
1 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/lib/chess-pgn.vala b/lib/chess-pgn.vala
index cfe1fb4..5e57751 100644
--- a/lib/chess-pgn.vala
+++ b/lib/chess-pgn.vala
@@ -239,15 +239,46 @@ public class PGN : Object
{
switch (tag_name)
{
+ case "WhiteTimeLeft":
+ if (int64.try_parse (tag_value) == false)
+ warning ("Invalid %s : %s in PGN, setting timer to infinity.", tag_name, tag_value);
+ else
+ game.tags.insert (tag_name, tag_value);
+ break;
+ case "BlackTimeLeft":
+ if (int64.try_parse (tag_value) == false)
+ warning ("Invalid %s : %s in PGN, setting timer to infinity.", tag_name, tag_value);
+ else
+ game.tags.insert (tag_name, tag_value);
+ break;
+ case "TimeControl":
+ if (int64.try_parse (tag_value) == true)
+ {
+ if (game.tags["WhiteTimeLeft"] != null && game.tags["BlackTimeLeft"] != null)
+ game.tags.insert (tag_name, tag_value);
+ }
+ else
+ warning ("Invalid %s : %s in PGN, setting timer to infinity.", tag_name, tag_value);
+ break;
case "X-GNOME-ClockType":
if (ClockType.string_to_enum (tag_value) == ClockType.INVALID)
{
warning ("Invalid clock type in PGN: %s, using a simple clock.", tag_value);
- tag_value = "simple";
+ game.tags.insert (tag_name, "simple");
}
break;
+ case "X-GNOME-TimerIncrement":
+ if (int64.try_parse (tag_value) == false)
+ {
+ warning ("Invalid timer increment in PGN: %s, using a simple clock.", tag_value);
+ game.tags["X-GNOME-ClockType"] = "simple";
+ game.tags.insert (tag_name, "0");
+ }
+ break;
+ default:
+ game.tags.insert (tag_name, tag_value);
+ break;
}
- game.tags.insert (tag_name, tag_value);
}
public PGN.from_string (string data) throws PGNError
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]