>From a57f74b4aacf96f5b626634e97a3cb0ddf94811e Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sun, 28 Jul 2019 21:13:23 -0700
Subject: [PROPOSED] Defend against CRLF in leap-seconds.list

(Thanks to Brian Inglis.)
* NEWS: Mention it.
* leapseconds.awk: Set RS to "\r?\n".
---
 NEWS            | 5 +++++
 leapseconds.awk | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 2337904..3414383 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,11 @@ Unreleased, experimental changes
     Hong Kong Winter Time, observed from 1941-10-01 to 1941-12-25,
     is now flagged as DST and is abbreviated HKWT not HKT.
 
+  Changes to code
+
+    The code now defends against CRLFs in leap-seconds.list.
+    (Thanks to Brian Inglis and Chris Woodbury.)
+
   Changes to commentary
 
     Nashville's newspapers dueled about the time of day in the 1950s.
diff --git a/leapseconds.awk b/leapseconds.awk
index af9b231..b73cb40 100755
--- a/leapseconds.awk
+++ b/leapseconds.awk
@@ -59,10 +59,10 @@ BEGIN {
   }
   monthlen[2] = 28
   monthlen[4] = monthlen[6] = monthlen[9] = monthlen[11] = 30
-}
 
-# In case the input has CRLF form a la NIST.
-{ sub(/\r$/, "") }
+  # In case the input has CRLF form a la NIST.
+  RS = "\r?\n"
+}
 
 /^#\tUpdated through/ || /^#\tFile expires on:/ {
     last_lines = last_lines $0 "\n"
-- 
2.20.1

