Fix worldcat links have spaces#12653
Merged
mekarpeles merged 2 commits intoMay 6, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to stop whitespace from being included in the generated WorldCat URL on edition pages (which is currently triggering ModSecurity as “abusive traffic”), by removing the whitespace-producing URL macro and generating the href directly.
Changes:
- Removes the
WorldcatUrlmacro and shifts URL construction intoWorldcatLink. - Updates the edition view template to pass a single
oclc_numberand use the renamedworldcat_linkvariable. - Refactors the
WorldcatLinkmacro to choose between OCLC vs ISBN URLs inline.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| openlibrary/templates/type/edition/view.html | Renames variables and changes the WorldCat macro invocation to use oclc_number and worldcat_link. |
| openlibrary/macros/WorldcatUrl.html | Deletes the URL-only macro that could inject leading whitespace into URLs. |
| openlibrary/macros/WorldcatLink.html | Inlines the WorldCat URL generation logic into the <a href=...> attribute. |
4387483 to
f13dcca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix. This is showing up in our modsecurity as "abusive traffic", but it's actually just the macro's whitespace being included in the URL. It appears some clients/browsers don't string the white space from the URL, and instead try to then go to a url like
openlibrary.org/ http://worldcat...Technical
Testing
Confirmed worldcat links still render correctly: https://testing.openlibrary.org/works/OL11327425W/Prisoner_in_paradise?edition=key%3A/books/OL10691191M
Screenshot
Stakeholders