From e8e713721628d127455fb339a98f1abe77b027ec Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Wed, 25 Mar 2020 10:18:09 -0400 Subject: [PATCH] rtutil: Fix parsing server URLs that include /REST/. --- conservancy_beancount/rtutil.py | 2 +- tests/test_rtutil.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/conservancy_beancount/rtutil.py b/conservancy_beancount/rtutil.py index 081d7f1..f154845 100644 --- a/conservancy_beancount/rtutil.py +++ b/conservancy_beancount/rtutil.py @@ -50,7 +50,7 @@ class RT: self.rt = rt_client urlparts = urlparse.urlparse(rt_client.url) try: - index = urlparts.path.index('/REST/') + index = urlparts.path.rindex('/REST/') except ValueError: base_path = urlparts.path.rstrip('/') + '/' else: diff --git a/tests/test_rtutil.py b/tests/test_rtutil.py index 87333e7..9aed048 100644 --- a/tests/test_rtutil.py +++ b/tests/test_rtutil.py @@ -121,3 +121,9 @@ def test_exists_caches(new_client): ]) def test_parse(rt, link, expected): assert rt.parse(link) == expected + +def test_uncommon_server_url_parsing(): + url = 'https://example.org/REST/1.0/' + client = testutil.RTClient(url + 'REST/1.0/') + rt = rtutil.RT(client) + assert rt.url(1).startswith(url)