Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hydra box does not use actual decoded query string params #105

Open
tpluscode opened this issue Nov 16, 2022 · 0 comments
Open

Hydra box does not use actual decoded query string params #105

tpluscode opened this issue Nov 16, 2022 · 0 comments

Comments

@tpluscode
Copy link
Contributor

I just stumbled upon a small problem with spaced encoded in query string parameters of IRI Template routes

Spaces in query can be encoded as %20 or +. In the latter case, it appears that they are not decoded by hydra-box but the plus sign is preserved in the value.

Here is the diff that solved my problem. At first I thought that the problem was in using req.params and not req.query but I assume that it could not, since a template variable can also be a segment? (is that actually supported, I don't remember). Thus, for now I added a replacer so that + does become a space but only when the given key is in fact a query string param.

Let me know if you think that the improvement should actually be in using req.query...

diff --git a/node_modules/hydra-box/lib/middleware/iriTemplate.js b/node_modules/hydra-box/lib/middleware/iriTemplate.js
index b725da2..100702b 100644
--- a/node_modules/hydra-box/lib/middleware/iriTemplate.js
+++ b/node_modules/hydra-box/lib/middleware/iriTemplate.js
@@ -65,13 +65,17 @@ function middleware ({ dataset, term, graph }) {
     const templateParams = clownface({ dataset: rdf.dataset() }).blankNode()
 
     Object.entries(req.params).forEach(([key, value]) => {
+      const isQueryParam = key in req.query
       const property = variablePropertyMap.get(key)
 
       if (!property) {
         return
       }
 
-      templateParams.addOut(property, createTermFromVariable({ template: iriTemplateNode, value }))
+      templateParams.addOut(property, createTermFromVariable({
+        template: iriTemplateNode,
+        value: isQueryParam ? value.replace(/\+/g, ' ') : value
+      }))
     })
 
     req.dataset = () => {

This issue body was partially generated by patch-package.

tpluscode added a commit to zazuko/cube-creator that referenced this issue Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant