drkane / datasette-reconcile

Adds a reconciliation API endpoint to Datasette, based on the Reconciliation Service API specification.
MIT License
22 stars 6 forks source link

view_url datasette-compatible escaping #25

Open frafra opened 1 year ago

frafra commented 1 year ago

Hi! Thanks for sharing such a useful plugin :)

I found out that IDs containing special characters are not escaped correctly in the URL when the endpoint is datasette itself (which is the default). For example, datasette will fail to load http://localhost/db/table/FA3/N/819, but it would work with http://localhost/db/table/FA3~2FN~2F819

I think an alternative variable should be made available, which is escaped according to Datasette, which should also be the default.

def tilde_encode(s: str) -> str:
    "Returns tilde-encoded string - for example ``/foo/bar`` -> ``~2Ffoo~2Fbar``"
    return "".join(_tilde_encoder(char) for char in s.encode("utf-8"))

-- https://github.com/simonw/datasette/blob/f0fadc28ddb9f82e5cc1ecaa51e8a342eb6dc528/datasette/utils/__init__.py#L1166-L1168

drkane commented 6 months ago

@frafa - sorry for the extremely long delay in looking at this.

If this is still relevant, could you give an example of how it would work? The view_url is defined in the service manifest, but it only defines it as <dbname>/<tablename>/{{id}}. The services that implement the reconciliation API (e.g. OpenRefine) are responsible for working out the URL from the ID that is given.

Is it that the ID returned by the query response should be tilde-encoded by default? I'm in two minds about this - on the one hand it would help for reconstructing the URL, but it might not be the right thing to do for other uses of the ID outside of datasette where it might be important that the slash remains. I'm not sure there's an easy way to make this user-configurable and still stay within the reconciliation API schema.