This project has moved. For the latest updates, please go here.

RdfParseException when searching for a string that includes \ characters.

Sep 15, 2015 at 8:30 PM
I'm 99% sure that I'm doing something wrong, but it's not immediately obvious to me what.

Using the current BrightStarDB release (1.11.0, installed in the project as a NuGet package) I am attempting to create a quick proof-of concept for something, but I'm running into an unexpected challenge., a minimal reproduction for which I include below:

Assuming an entity like this,
[Entity]
interface IProblemEntity
{
    String Id { get; }

    String UserEntered { get; set; }
}
The following very simple code causes an RdfParseException to be thrown.
    static void Main(string[] args)
    {
        var dataContext = new MyEntityContext("Type=embedded;StoresDirectory=c:\\brightstardb;StoreName=test");

        var thisShouldBeAValidString = "The client\\server configuration";

        var problem = new ProblemEntity { UserEntered = thisShouldBeAValidString};

        dataContext.ProblemEntities.Add(problem);
        dataContext.SaveChanges();

        var retrieved = dataContext.ProblemEntities.First(p => p.UserEntered == thisShouldBeAValidString);

        Console.WriteLine("The value retrieved was: {0}", retrieved.UserEntered);
    }
The same problem occurs when looking for a substring that contains a \ character (for example var retrieved = dataContext.ProblemEntities.First(p => p.UserEntered.Contains("client\server"))).

Am I doing it wrong? Do strings need to be escaped/sanitized somehow before being used in a query?

All comments and suggestions welcomed.
Regards,
Richard
Coordinator
Sep 18, 2015 at 5:49 PM
Hi Richard,

Thank you for the detailed bug report and please accept my apologies for the delay in replying.

With the code you provided I was able to reproduce the issue and create a fix (see https://github.com/BrightstarDB/BrightstarDB/issues/242). The problem was that the code generating SPARQL queries from the LINQ was not properly escaping backslash (and some other characters that are required to be escaped by the spec). The fix is now pushed to the develop branch and it will be in the next release.

Cheers

Kal
Marked as answer by RichardJFoster on 9/21/2015 at 5:29 AM
Sep 21, 2015 at 1:28 PM
Ah! Excellent!

Thanks Kal. I guess I wasn't being as dumb as I thought I was. :-) (Because it's the first time I have played directly with an Rdf data store I thought it was significantly more likely to have been my mistake than anyone else's oversight.)

I look forward to the next release, when the fix appears. Just in case anyone else runs into the same problem before then and does not want to build the Dev branch from source, I temporarily worked around the problem by using a regular expression match (thereby eliminating the \ characters) instead. It's not ideal, but for the "proof of concept" it was good enough.

Regards,
Richard