Repository: falconry/falcon
Pull request #1289 (2018-05-14 20:06:34)

fix(request): Change RequestOptions.strip_url_path_trailing_slash default
Set the default to False #1267

codecov[bot]: # [Codecov](https://codecov.io/gh/falconry/falcon/pull/1289?src=pr&el=h1) Report
> Merging [#1289](https://codecov.io/gh/falconry/falcon/pull/1289?src=pr&el=desc) into [master](https://codecov.io/gh/falconry/falcon/commit/899c31f228df78c45e2fd4da28df400558c85a48?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/falconry/falcon/pull/1289/graphs/tree.svg?width=650&token=zOtkfNQ3h6&height=150&src=pr)](https://codecov.io/gh/falconry/falcon/pull/1289?src=pr&el=tree)

```diff
@@          Coverage Diff           @@
##           master   #1289   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files          39      39           
  Lines        2514    2514           
  Branches      378     378           
======================================
  Hits         2514    2514
```


| [Impacted Files](https://codecov.io/gh/falconry/falcon/pull/1289?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [falcon/request.py](https://codecov.io/gh/falconry/falcon/pull/1289/diff?src=pr&el=tree#diff-ZmFsY29uL3JlcXVlc3QucHk=) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/falconry/falcon/pull/1289?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/falconry/falcon/pull/1289?src=pr&el=footer). Last update [899c31f...b90dff1](https://codecov.io/gh/falconry/falcon/pull/1289?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/falcon/request.py b/falcon/request.py
index e725e95..e0fd1cc 100644
--- a/falcon/request.py
+++ b/falcon/request.py
@@ -1762,9 +1762,9 @@ class RequestOptions(object):
             encoded in alternative formats in which the comma character
             is significant.
 
-        strip_url_path_trailing_slash: Set to ``False`` in order to
-            retain a trailing slash, if present, at the end of the URL
-            path (default ``True``). When this option is enabled,
+        strip_url_path_trailing_slash: Set to ``True`` in order to
+            strip the trailing slash, if present, at the end of the URL
+            path (default ``False``). When this option is enabled,
             the URL path is normalized by stripping the trailing slash
             character. This lets the application define a single route
             to a resource for a path that may or may not end in a
@@ -1796,6 +1796,6 @@ class RequestOptions(object):
         self.keep_blank_qs_values = False
         self.auto_parse_form_urlencoded = False
         self.auto_parse_qs_csv = True
-        self.strip_url_path_trailing_slash = True
+        self.strip_url_path_trailing_slash = False
         self.default_media_type = DEFAULT_MEDIA_TYPE
         self.media_handlers = Handlers()


Test patch:
diff --git a/tests/test_options.py b/tests/test_options.py
index b039428..d8fdc0d 100644
--- a/tests/test_options.py
+++ b/tests/test_options.py
@@ -11,7 +11,7 @@ class TestRequestOptions(object):
         assert not options.keep_blank_qs_values
         assert not options.auto_parse_form_urlencoded
         assert options.auto_parse_qs_csv
-        assert options.strip_url_path_trailing_slash
+        assert not options.strip_url_path_trailing_slash
 
     @pytest.mark.parametrize('option_name', [
         'keep_blank_qs_values',
diff --git a/tests/test_request_attrs.py b/tests/test_request_attrs.py
index ce70194..f9e73a8 100644
--- a/tests/test_request_attrs.py
+++ b/tests/test_request_attrs.py
@@ -268,9 +268,10 @@ class TestRequestAttributes(object):
             query_string=self.qs,
             headers=self.headers))
 
+        relative_trailing_uri = self.path + '/?' + self.qs
         # NOTE(kgriffs): Call twice to check caching works
-        assert req_noapp.relative_uri == self.relative_uri
-        assert req_noapp.relative_uri == self.relative_uri
+        assert req_noapp.relative_uri == relative_trailing_uri
+        assert req_noapp.relative_uri == relative_trailing_uri
 
         options = RequestOptions()
         options.strip_url_path_trailing_slash = False
diff --git a/tests/test_uri_templates.py b/tests/test_uri_templates.py
index 95c8c4e..7cc56b5 100644
--- a/tests/test_uri_templates.py
+++ b/tests/test_uri_templates.py
@@ -356,19 +356,27 @@ def test_single_trailing_slash(client):
     resource2 = IDResource()
     client.app.add_route('/2/{id}/', resource2)
     result = client.simulate_get('/2/123/')
-    assert result.status == falcon.HTTP_200
-    assert resource2.called
-    assert resource2.id == '123'
-    assert resource2.req.path == '/2/123'
+    assert result.status == falcon.HTTP_404
+    assert not resource2.called
+    assert resource2.id is None
 
     resource3 = IDResource()
-    client.app.add_route('/3/{id}', resource3)
+    client.app.add_route('/3/{id}/', resource3)
+    client.app.req_options.strip_url_path_trailing_slash = True
     result = client.simulate_get('/3/123/')
     assert result.status == falcon.HTTP_200
     assert resource3.called
     assert resource3.id == '123'
     assert resource3.req.path == '/3/123'
 
+    resource4 = IDResource()
+    client.app.add_route('/4/{id}', resource4)
+    client.app.req_options.strip_url_path_trailing_slash = False
+    result = client.simulate_get('/4/123/')
+    assert result.status == falcon.HTTP_404
+    assert not resource4.called
+    assert resource4.id is None
+
 
 def test_multiple(client):
     resource = NameResource()