surrealdb / surrealdb

A scalable, distributed, collaborative, document-graph database, for the realtime web
https://surrealdb.com
Other
26.64k stars 850 forks source link

Bug: Import / Export doesn't work with special characters and futures #1790

Closed Micnubinub closed 1 year ago

Micnubinub commented 1 year ago

Describe the bug

Importing seems to have issues when there are special chars like backslashes and dollar signs or futures... I think they need to be escaped in the export. Also found that futures also can't be imported

Steps to reproduce

UPDATE company:rglau8wcgs0e1hc6sc71 CONTENT { abn: '49432246940', coverPhoto: file:0q7s00penws61tjq1ka0, email: 'Louie.Beahan37@yahoo.com', id: company:rglau8wcgs0e1hc6sc71, logo: file:logo, managers: [], mobile: '01232 234324', moto: 'amet', name: 'Heaney, Bradtke and Parisian', owner: user:2I3TJ0PjkOR2D44U0jwbErNePcg1, paymentMethods: [], stripeID: 'd@TIS$KaZ}', stripeId: 'seCUS<l7\l', team: [user:BzXcS5jz01QOLWOoh0KOUd3bDIv1, user:rjK67jm2kdhRjA4OTr9hbcfaR1w1, user:vvKPlM3Zegamznc9UnYEwFN7IUp2, user:xD9XVmO1CoRGAElHjU42gGQG0Zj1, user:xp4JGOy51nggEPnN9K4YPzqdXJn1], website: 'ndispro.com' };

Error message is: There was a problem with the database: Parse error on line 3 at character 36 when parsing 'CONTENT { abn: '49432246940', coverPhoto: file:0q7s00penws61tjq1ka0, email: 'Louie.Beahan37@yahoo.co'

With the future my original definition was:

DEFINE FIELD amountDonated ON TABLE charity VALUE <future> {<float> (select math::fixed(math::sum(amount), 2) as t from charityDonation where charity=$parent.id group all)[0].t};

The export was:

DEFINE FIELD amountDonated ON charity VALUE <future> { <float> (SELECT math::fixed(math::sum(amount), 2) AS t FROM charityDonation WHERE charity = $parent.id GROUP BY )[0].t };

The error message is:

There was a problem with the database: Parse error on line 1 at character 38 when parsing 'VALUE <future> { <float> (SELECT math::fixed(math::sum(amount), 2) AS t FROM charityDonation WHERE c'

Expected behaviour

Export values, then Import with no errors and the same values

SurrealDB version

1.0.0-beta.9+20230402.5eafebd

Contact Details

lindelwencube.ln@gmail.com

Is there an existing issue for this?

Code of Conduct

kearfy commented 1 year ago

Interestingly enough, 'seCUS<l7\l' has to be 'seCUS<l7\\l', I'm not exactly sure why that's the case though... It only happens with the specific characters, not sure what the meaning of every escaped character it out of my head...

--broken
return 'seCUS<l7\l'; -- as in the example
return 'seCUS<l7\a';

--works
return 'seCUS<l7\b';

See comment by @rushmorem ~Observation on the other issue you are pointing out, I'm not sure why GROUP ALL was changed to GROUP BY. The space at the end does indicate to me that surrealdb was trying to change it to a specific field, but failed to do so?~

Gonna ping @tobiemh for this one

rushmorem commented 1 year ago

I'm not sure why GROUP ALL was changed to GROUP BY

@kearfy It wasn't. It was an issue in the Display implementation for Groups. It has since been fixed on main.

kearfy commented 1 year ago

Ah, I had not seen that commit just yet. Thanks @rushmorem!

tobiemh commented 1 year ago

I'm going to close this as this has been fixed in https://github.com/surrealdb/surrealdb/pull/1788. The issue was that GROUP ALL statements were not being output properly, resulting in GROUP BY being written instead. If you change the GROUP BY to GROUP ALL, then the import will work @Micnubinub.

@kearfy regarding the issue of escaped characters, we only support \b, \f, \n, \r, \t characters within strings, and allow any other unicode character using the format \u123456 (except for a surrogate code points, U+D800 to U+DFFF which are reserved for use by UTF-18). Any other control character must be escaped. This is so that strings can be output to JSON correctly without issue,