Blob Blame History Raw
From 6109ad5a54359262010d01f2e0175d928bd70962 Mon Sep 17 00:00:00 2001
From: Alex DeJarnatt <adejarnatt@gmail.com>
Date: Fri, 7 Jun 2019 11:16:50 -0400
Subject: [PATCH] Fix Issue #21

---
 puz.py   | 9 ++++++---
 tests.py | 4 ++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/puz.py b/puz.py
index 99a6a71..bbe32a4 100644
--- a/puz.py
+++ b/puz.py
@@ -282,6 +282,9 @@ def tobytes(self):
 
         return s.tobytes()
 
+    def version_tuple(self):
+      return tuple(map(int, self.version.decode(ENCODING).split('.')))
+
     def has_rebus(self):
         return self.rebus().has_rebus()
 
@@ -341,7 +344,7 @@ def header_cksum(self, cksum=0):
     def text_cksum(self, cksum=0):
         # for the checksum to work these fields must be added in order with
         # null termination, followed by all non-empty clues without null
-        # termination, followed by notes (but only for version 1.3)
+        # termination, followed by notes (but only for version >= 1.3)
         if self.title:
             cksum = data_cksum(self.title.encode(ENCODING) + b'\0', cksum)
         if self.author:
@@ -353,8 +356,8 @@ def text_cksum(self, cksum=0):
             if clue:
                 cksum = data_cksum(clue.encode(ENCODING), cksum)
 
-        # notes included in global cksum only in v1.3 of format
-        if self.version.decode(ENCODING) == '1.3' and self.notes:
+        # notes included in global cksum starting v1.3 of format
+        if self.version_tuple() >= (1,3) and self.notes:
             cksum = data_cksum(self.notes.encode(ENCODING) + b'\0', cksum)
 
         return cksum
diff --git a/tests.py b/tests.py
index e5862e8..8c00a77 100755
--- a/tests.py
+++ b/tests.py
@@ -73,6 +73,10 @@ def test_junk_at_end_of_puzzle(self):
         p.load(data)
         self.assertEqual(p.postscript, b'\r\n\r\n')
 
+    def test_v1_4(self):
+      p = puz.read('testfiles/nyt_v1_4.puz')
+      p.tobytes()
+
     def test_save_empty_puzzle(self):
         ''' confirm an empty Puzzle() can be saved to a file '''
         p = puz.Puzzle()