From 389ff033ec5a69faf9f95377c66527ce8df13a31 Mon Sep 17 00:00:00 2001 From: Andy Chosak Date: Mon, 6 Nov 2017 11:21:22 -0500 Subject: [PATCH] allow multiple dashes in section names This commit modifies the expected URL pattern for reg section labels so that instead of supporting only e.g. "1005-a" it also supports sections like "1005-a-interp". This fixes some 500 errors that were being generated due to a "1005-Appendices-Interp" section in Reg E. You can confirm that this works to view diffs in the most recent Reg E content in regulations-stub by hitting this URL locally: http://localhost:8000/eregulations/diff/1005-2/2016-24506/2016-24503_20181001?from_version=2016-24506#1005-2-a The section label is passed around the code in various places so it's possible that adding this flexibility might break something else downstream. All current unit tests pass with this change, however, so I'd rather enable this (which seems like a reasonable assumption, unless there's some section naming guidelines somewhere that are being violated) and handle errors as they come up. --- regulations/tests/urls_test.py | 6 ++++++ regulations/urls.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/regulations/tests/urls_test.py b/regulations/tests/urls_test.py index a5c78c1b..88bba567 100644 --- a/regulations/tests/urls_test.py +++ b/regulations/tests/urls_test.py @@ -33,3 +33,9 @@ def test_diff_url(self): args=('201-2', '2011-1738_20121011', '2012-22345_20131022')) self.assertEqual( r, '/diff/201-2/2011-1738_20121011/2012-22345_20131022') + + def test_diff_url_supports_multiple_dashes(self): + r = reverse( + 'chrome_section_diff_view', + args=('201-Interp-XYZ', '2011-1738', '2012-22345')) + self.assertEqual(r, '/diff/201-Interp-XYZ/2011-1738/2012-22345') diff --git a/regulations/urls.py b/regulations/urls.py index 479190d7..01ec81cb 100644 --- a/regulations/urls.py +++ b/regulations/urls.py @@ -28,7 +28,7 @@ notice_pattern = meta_version % 'notice_id' reg_pattern = r'(?P[\d]+)' -section_pattern = r'(?P[\d]+[-][\w]+)' +section_pattern = r'(?P[\d]+[-][\w-]+)' interp_pattern = r'(?P[-\d\w]+[-]Interp)' paragraph_pattern = r'(?P[-\d\w]+)' subterp_pattern = r'(?P[\d]+-(Appendices|Subpart(-[A-Z]+)?)-Interp)'