Skip to content

🐛 Preserve URI values in Bulkrax subject parsing - #122

Merged
ShanaLMoore merged 2 commits into
mainfrom
i73-bulkrax-uri-capitalization
Sep 17, 2026
Merged

ShanaLMoore merged 2 commits into
mainfrom
i73-bulkrax-uri-capitalization

Conversation

@ShanaLMoore

Copy link
Copy Markdown
Contributor

Story

Refs

🐛 Preserve URI values in Bulkrax subject parsing

440ebd2

Bulkrax's ApplicationMatcher#parse_subject lowercases the entire
value then capitalizes the first character. This turns
"http://id.loc.gov/..." into "Http://id.loc.gov/...", breaking
every downstream check that pattern-matches on the URI scheme,
including UtkUriLabelIndexing.

Decorate parse_subject to return URIs verbatim while still applying
sentence-casing to plain text subjects. The regex guards on
http(s):// which covers all URI schemes in UTK's controlled
vocabulary fields.

Expected Behavior Before Changes

Bulkrax CSV import of a subject URI like http://id.loc.gov/authorities/subjects/sh85101348 stores Http://id.loc.gov/authorities/subjects/sh85101348 in parsed metadata. The capitalized scheme breaks URI detection in UtkUriLabelIndexing and any other code pattern-matching on http://.

Expected Behavior After Changes

URI values in subject fields are preserved verbatim through Bulkrax's parsing pipeline. Plain text subjects still receive sentence-casing ("photography" becomes "Photography").

Screenshots / Video

No UI change. Data parsing fix verified by specs.

Notes

  • The root cause is in Bulkrax's ApplicationMatcher#parse_subject (line 69-73 of application_matcher.rb in Bulkrax 9.5.1), which was written assuming subjects are plain text, not URIs
  • A secondary issue compounds this: Importer#field_mapping is blank in the DB, so Importer#mapping falls back to default_field_mapping which auto-sets parsed: true for any field with a parse_* method, ignoring UTK's custom mappings that omit the parsed flag
  • Worth contributing the URI-aware fix upstream to Bulkrax; tagged contribute back

🤖 Generated with Claude Code

https://claude.ai/code/session_017ShYMAGZMpZ5mFuqmAuckf

Bulkrax's ApplicationMatcher#parse_subject lowercases the entire
value then capitalizes the first character. This turns
"http://id.loc.gov/..." into "Http://id.loc.gov/...", breaking
every downstream check that pattern-matches on the URI scheme,
including UtkUriLabelIndexing.

Decorate parse_subject to return URIs verbatim while still applying
sentence-casing to plain text subjects. The regex guards on
http(s):// which covers all URI schemes in UTK's controlled
vocabulary fields.

Ref:
- #73

Assisted by: Claude Opus 4.6
@ShanaLMoore ShanaLMoore added contribute back code needs to be contributed to open source patch-ver for release notes labels Sep 16, 2026
@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown

Test Results

      4 files  ±    0        4 suites  ±0   46s ⏱️ -1s
119 012 tests +1 589  119 012 ✅ +1 589  0 💤 ±0  0 ❌ ±0 
    998 runs  +   15      998 ✅ +   15  0 💤 ±0  0 ❌ ±0 

Results for commit 7bb2b37. ± Comparison against base commit 444113a.

♻️ This comment has been updated with latest results.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped, matches the stated expected behavior, and includes direct and integration-level spec coverage for the regression.

Pull request overview

This PR fixes Bulkrax subject parsing so URI values (e.g., http://id.loc.gov/...) are preserved verbatim rather than being sentence-cased into an invalid URI scheme (Http://...). This prevents downstream URI-detection logic (e.g., checks that rely on http:// / https://) from breaking while keeping sentence-casing behavior for plain-text subjects.

Changes:

  • Add a Bulkrax::ApplicationMatcher decorator that returns http(s):// subjects unchanged (aside from whitespace stripping), delegating to Bulkrax’s original behavior for plain text.
  • Add RSpec coverage validating URI preservation, whitespace stripping, plain-text sentence-casing, blank handling, and integration through #result.
File summaries
File Description
app/matchers/bulkrax/application_matcher_decorator.rb Prepends an override of parse_subject to preserve http(s):// URIs verbatim while retaining Bulkrax’s original behavior for non-URI values.
spec/matchers/bulkrax/application_matcher_decorator_spec.rb Adds specs ensuring URI values aren’t capitalized and verifying behavior for plain text, whitespace, blanks, and the full matcher pipeline.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is small, targeted, and backed by focused specs validating both the URI fix and unchanged plain-text behavior.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread app/matchers/bulkrax/application_matcher_decorator.rb Outdated
Downcase the entire URI instead of returning it verbatim so that
capitalized schemes from either Bulkrax's sentence-casing or from
the CSV itself (Http://, HTTP://) are normalized to lowercase,
which UriLabelResolver requires to resolve labels.

Assisted by: Claude Opus 4.6
@ShanaLMoore
ShanaLMoore force-pushed the i73-bulkrax-uri-capitalization branch from 90c916b to 7bb2b37 Compare September 17, 2026 19:36
@ShanaLMoore
ShanaLMoore marked this pull request as ready for review September 17, 2026 20:10

@laritakr laritakr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a followup ticket to get Bulkrax updated so we can get this cleaned up? I'd anticipate more work coming too.

@ShanaLMoore

Copy link
Copy Markdown
Contributor Author

Do we have a followup ticket to get Bulkrax updated so we can get this cleaned up? I'd anticipate more work coming too.

I'll make a general placeholder ticket to update Bulkrax: #133

Here is the equivalent PR this is decorating: samvera/bulkrax#1214

@ShanaLMoore
ShanaLMoore merged commit d03ef60 into main Sep 17, 2026
14 checks passed
@ShanaLMoore
ShanaLMoore deleted the i73-bulkrax-uri-capitalization branch September 17, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribute back code needs to be contributed to open source patch-ver for release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants