Repository: internetarchive/openlibrary

Issue:
Hyphenated/spaced user names in url breaks list functionality
<!-- What problem are we solving? What does the experience look like today? What are the symptoms? -->
I've had two instances of hyphenated user names potentially causing an issue with lists. It is possible to create lists, but not possible to add or make any further modifications once created. 
### Evidence / Screenshot (if possible)

### Relevant url?
https://openlibrary.org/people/agent-lisa
https://openlibrary.org/people/ina-noft

### Steps to Reproduce
<!-- What steps caused you to find the bug? -->
1. Create user account with a hyphenated name.
2. Create a list.
3. Add more to the list.

<!-- What actually happened after these steps? What did you expect to happen? -->
* Actual: Nothing. 
* Expected: List should function normally

### Details

- **Logged in (Y/N)?** 
- **Browser type/version?** 
- **Operating system?** 
- **Environment (prod/dev/local)?** prod
<!-- If not sure, put prod -->

### Proposal & Constraints
<!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->

### Related files
<!-- Files related to this issue; this is super useful for new contributors who might want to help! If you're not sure, leave this blank; a maintainer will add them. -->

### Stakeholders
<!-- @ tag stakeholders of this bug -->



Discussion:
 Maybe we should percent encode all special characters in our URLs.  There's a similar issue for publishers with special characters in their names (#2202).
Also seen with slashes in subject urls.
This keeps coming up, but somehow is never fixed: #333, #727, #2202, #2302, #2932, #5613 all relate to the same thing. Need to urlencode (or strip) the breaking characters in subject and publisher urls. Of course none of this would be necessary if we were to stop treating publishers and subjects as free text.

Resolving patch:
diff --git a/openlibrary/plugins/openlibrary/lists.py b/openlibrary/plugins/openlibrary/lists.py
--- a/openlibrary/plugins/openlibrary/lists.py
+++ b/openlibrary/plugins/openlibrary/lists.py
@@ -54,7 +54,7 @@ def render(self, doc, lists):
         return render_template("lists/lists.html", doc, lists)
 
 class lists_delete(delegate.page):
-    path = r"(/people/\w+/lists/OL\d+L)/delete"
+    path = r"(/people/[^/]+/lists/OL\d+L)/delete"
     encoding = "json"
 
     def POST(self, key):
@@ -273,7 +273,7 @@ def get_list_seeds(key):
 
 
 class list_seeds(delegate.page):
-    path = r"(/people/\w+/lists/OL\d+L)/seeds"
+    path = r"(/people/[^/]+/lists/OL\d+L)/seeds"
     encoding = "json"
 
     content_type = "application/json"
@@ -352,7 +352,7 @@ def get_list_editions(key, offset=0, limit=50, api=False):
 
 
 class list_editions_json(delegate.page):
-    path = r"(/people/\w+/lists/OL\d+L)/editions"
+    path = r"(/people/[^/]+/lists/OL\d+L)/editions"
     encoding = "json"
 
     content_type = "application/json"
@@ -399,7 +399,7 @@ def make_collection(size, entries, limit, offset, key=None):
 
 
 class list_subjects_json(delegate.page):
-    path = r"(/people/\w+/lists/OL\d+L)/subjects"
+    path = r"(/people/[^/]+/lists/OL\d+L)/subjects"
     encoding = "json"
     content_type = "application/json"
 
@@ -445,7 +445,7 @@ class list_editions_yaml(list_subjects_json):
 
 
 class lists_embed(delegate.page):
-    path = r"(/people/\w+/lists/OL\d+L)/embed"
+    path = r"(/people/[^/]+/lists/OL\d+L)/embed"
 
     def GET(self, key):
         doc = web.ctx.site.get(key)
@@ -455,7 +455,7 @@ def GET(self, key):
 
 
 class export(delegate.page):
-    path = r"(/people/\w+/lists/OL\d+L)/export"
+    path = r"(/people/[^/]+/lists/OL\d+L)/export"
 
     def GET(self, key):
         lst = web.ctx.site.get(key)


Test patch: