# URL encoding of strings containing a url

**URL:** <https://community.stardog.com/t/url-encoding-of-strings-containing-a-url/1420>\
**Category:** Support\
**Created:** [December 11, 2018, 10:13pm UTC](https://community.stardog.com/t/url-encoding-of-strings-containing-a-url/1420 "2018-12-11T22:13:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicholsn](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/nicholsn/32/284_2.png) [@nicholsn](https://community.stardog.com/u/nicholsn)\
**Post date:** [December 11, 2018, 10:13pm UTC](https://community.stardog.com/t/url-encoding-of-strings-containing-a-url/1420/1 "2018-12-11T22:13:05Z")

</div>

I'm trying to generate a url encoded string using a sparql query. My goal is to have a link into the stardog webui, but this could be for any service that takes a URI as an argument. Here is an example query

```auto
select *
where {
    ?dataset a dcat:Dataset ;
    bind(concat("http://localhost:5820/mydb#!/browse/resource/", encode_for_uri(str(?dataset))) as ?kg)
}

```

The result that I am looking for is:

`http://localhost:5820/mydb#!/browse/resource/http%3A%2F%2Ffoo.bar.com%2FmyIRI`

But what I get is:

`http://localhost:5820/mydb#!/browse/resource/http://foo.bar.com/myIRI`

Is there any built in function I am missing that will correctly encode a string that contains an http url?

---

<div class="post-metadata">

**Author:** ![gatemezing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/gatemezing/32/177_2.png) [@gatemezing](https://community.stardog.com/u/gatemezing)\
**Post date:** [December 11, 2018, 10:44pm UTC](https://community.stardog.com/t/url-encoding-of-strings-containing-a-url/1420/2 "2018-12-11T22:44:12Z")

</div>

Per the W3C REC [1], the ENCODE\_FOR\_URI returns a simple literal with the lexical form obtained from the lexical form of its input after translating reserved characters according to the [fn:encode-for-uri](http://www.w3.org/TR/xpath-functions/#func-encode-for-uri) function

So normally from your sample, you should get what you were expecting, http%3A%2F%[2Ffoo.bar.com](http://2Ffoo.bar.com)%2FmyIRI

[1] [SPARQL 1.1 Query Language](https://www.w3.org/TR/sparql11-query/#func-encode)

---

<div class="post-metadata">

**Author:** ![nicholsn](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/nicholsn/32/284_2.png) [@nicholsn](https://community.stardog.com/u/nicholsn)\
**Post date:** [December 12, 2018, 4:50pm UTC](https://community.stardog.com/t/url-encoding-of-strings-containing-a-url/1420/3 "2018-12-12T16:50:08Z")

</div>

@gatemezing, right but that is not the behavior I am observing in stardog.

Is anyone able to replicate my issue? For example using the following triple, query, and result:

```auto
<http://foo.bar.com> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "some string" .

```

```auto
select ?s ?s1 ?o ?o1
where {
    ?s ?p ?o .
    bind(encode_for_uri(str(?s)) as ?s1)
    bind(encode_for_uri(str(?o)) as ?o1)
}

```

 ![27%20AM](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/1X/72e9c51bb05d7c077afa2d518e1ccbf0469db3b7.jpeg)

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [December 12, 2018, 5:13pm UTC](https://community.stardog.com/t/url-encoding-of-strings-containing-a-url/1420/4 "2018-12-12T17:13:38Z")

</div>

Hi Nolan,

We are able to reproduce this issue on our side, and I am creating a ticket to address it. Thanks for the report.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [December 26, 2018, 5:13pm UTC](https://community.stardog.com/t/url-encoding-of-strings-containing-a-url/1420/5 "2018-12-26T17:13:45Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
