Triply-Dev / YASGUI.YASQE-deprecated

Deprecated, see https://github.com/TriplyDB/Yasgui for the Yasgui monorepo
MIT License
73 stars 36 forks source link

Wrong prefix replacement in "properties" autocompleter #88

Closed tlorenzetti closed 8 years ago

tlorenzetti commented 8 years ago

Let's suppose I have this prefixes declarated in my query

prefix my: <http://myfirstprefix#>
prefix mypref: <http://mysecondprefix#>

when I try to autocomplete properties starting with mypref: the autocompletionString that I obtain after preProcessToken of properties autocompleter is http://myfirstprefix#ref: It seems that preProcessToken identifies the wrong prefix and replaces just my (in mypref:) with its namespace instead of replacing the entire prefix.

I noticed this when I declarated both rdf and rdfs and I tried to autocomplete rdfs:: The request to lov API was http://lov.okfn.org/dataset/lov/api/v2/autocomplete/terms?q=http%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3A&page=1&type=property where, as you can see, it uses the rdf namespace (instead of rdfs).

tlorenzetti commented 8 years ago

I identified the error in preprocessResourceTokenForCompletion (preproceutils.js line 28-34)

for (var prefix in queryPrefixes) {
    if (token.string.indexOf(prefix) == 0) {
        token.autocompletionString = queryPrefixes[prefix];
        token.autocompletionString += token.string.substring(prefix.length + 1);
        break;
    }
}

To build autocompletionString it just takes the first prefix encountered in queryPrefixes. To fix this, I think it's enough to change if (token.string.indexOf(prefix) == 0) { to if (token.string.indexOf(prefix + ":") == 0) {

LaurensRietveld commented 8 years ago

thanks for the thorough bug report! It should be fixed now (and released as v2.11.2)