Fix invalid IRI generation for content variants with special characters #230
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.
Problem
When registering DataID versions with content variants containing special characters (such as URLs with colons, slashes, or hash symbols), the system generated invalid IRIs that caused JSON-LD deserialization errors:
The root cause was that content variant values were being directly concatenated into IRIs without proper URL encoding, resulting in IRIs containing unescaped special characters that violate RFC 3986 URI syntax rules.
Solution
This PR adds proper URL encoding using
encodeURIComponent()to all user-provided values before they are used in IRI construction. The fix is applied in theautofillFileIdentifiersfunction indataid-autocomplete.js.Example Transformation
Before (invalid):
After (valid):
Changes
Modified
server/app/api/lib/dataid-autocomplete.js: AddedencodeURIComponent()to encode:Added
server/app/tests/test.autocomplete.js: Comprehensive test suite with three test cases::,/,#) in content variant valuesTesting
All new tests pass successfully:
cd server NODE_PATH=../public/node_modules:node_modules npx uvu app/tests test.autocomplete.jsImpact
Fixes the issue where posting DataIDs with content variants containing URLs or other special characters would fail with IRI validation errors.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
mapbox-node-binary.s3.amazonaws.comnode-pre-gyp(dns block)scarf.shnode ./report.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Fixes #226
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.