Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Capacitor] Forward slash stripped from string values when inserting/updating rows on Android device #61

Open
jarrodkoch opened this issue Oct 7, 2021 · 8 comments

Comments

@jarrodkoch
Copy link

Hello,

I am attempting to use this plugin as an alternative to another one which I cannot continue to use due to non-support of the Android V30 SDK, which is required as of November of this year. The plugin is being utilized in an Ionic/Angular hybrid application targeting iOS and Android. Everything seemed fine with this as a direct replacement in iOS, but on Android, values inserted/updated into text columns which contain the / character (forward slash) end up with the forward slash character stripped out when they get into the database.

I attempted various escape sequences, but everything I tried resulted in all / characters being stripped out.

I am unable to find any configuration/settings which might cause this behavior. Also, it is occurring only on Android.

Company policy does not allow for providing you access to the application source, and I'm not sure how I might provide a smaller reproduction (if I had one) as I don't know you you might consume it.

@brodycj
Copy link
Contributor

brodycj commented Oct 7, 2021

Hello @jarrodkoch thanks for reporting. Yes I would also not want you to post any company source code in an issue like this which is publicly accessible.

Considering that I have recently tested with the forward slash (/) character with no issues, I cannot see how I may be able to reproduce this issue with some more clues. For free support I would need to keep the discussions in publicly accessible issues like this one.

For private, commercial support I think your company has already reached out to me. In case anyone else may be interested in private support please reach out to: [email protected]

@jarrodkoch
Copy link
Author

I'm running into gradle problems which will take me until November to solve, which is too late, so here's the gist of my problem.
image
The value that goes into the database is supposed to be the same as what comes out, but a/b becomes ab.

@jarrodkoch
Copy link
Author

Here is the service implementation
image

@jarrodkoch
Copy link
Author

I have a "small" reproduction (it's mostly boilerplate).

https://github.com/jarrodkoch/sqlite

This is an ionic hybrid app. I'm not sure how familiar you are with these. I'm hoping these steps will work for you without further fiddling. Note that you will need Android Studio installed to build the app.

After you have the repo pulled locally, run 'npm ci' within the repo's directory to get the project dependencies. After that, run 'ionic capacitor build', and follow the prompts. You will be building for Android. This will open the project in Android Studio once it is built, and from there you can deploy to your device. The UI is very basic. Inside the black border in the center is an input field. Input a value, and tapping submit will insert this value into sqlite and read the value back from sqlite, and display it on the screen. If the value contains a /, it will be stripped out on insertion into the database.

The logic most likely to be interesting to you is located in ./src/service/database.service.ts.

@brodycj brodycj changed the title Forward slash stripped from string values when inserting/updating rows on Android device [Capacitor] Forward slash stripped from string values when inserting/updating rows on Android device Oct 7, 2021
@brodycj
Copy link
Contributor

brodycj commented Oct 7, 2021

Hi thanks for the reproduction. I have not tested or supported this plugin with Ionic Capacitor before and am not in a position to promise anything outside of the commercial support at this time.

@jarrodkoch
Copy link
Author

@brodybits slogged through creating a similar ionic/cordova test app and I do not see the behavior on that platform of the forward slash characters being stripped out. If it was not your intent to support capacitor with this plugin feel free to close this issue.

@jarrodkoch
Copy link
Author

I'll leave the capacitor test repo in place if you want to play around with it at all.

@itbeyond
Copy link

itbeyond commented Sep 14, 2023

I have just come across this issue!

This is what Capacitor is sending according the the logger

To native (Cordova plugin): callbackId: SQLitePlugin53370136, service: SQLitePlugin, action: fj:10;extra, actionArgs: [1,2,"BEGIN",0,"insert or replace into settings(rowid, id, value) VALUES((SELECT rowid from settings WHERE id = ?), ?,?)",3,"data:storage","data:storage","{\"location\":\"SD0\",\"available\":4008894464,\"path\":\"\/storage\/emulated\/0\/Android\/data\/xx.xxx.xxx.xxx.xxx\",\"test\":\"\/storage\/11FB-0B1C\/Android\/data\/xx.xxx.xxx.xxx.xxx\"}","extra"]
To native (Cordova plugin): callbackId: SQLitePlugin53370137, service: SQLitePlugin, action: fj:5;extra, actionArgs: [1,1,"COMMIT",0,"extra"]

Then I run a get and this is what is sent

To native (Cordova plugin): callbackId: SQLitePlugin53370138, service: SQLitePlugin, action: fj:8;extra, actionArgs: [1,2,"BEGIN",0,"SELECT value FROM settings where id = ?",1,"data:storage","extra"]
To native (Cordova plugin): callbackId: SQLitePlugin53370139, service: SQLitePlugin, action: fj:5;extra, actionArgs: [1,1,"COMMIT",0,"extra"]

Which returns:

{
    "location": "SD0",
    "available": 4008894464,
    "path": "storageemulated0Androiddataxx.xxx.xxx.xxx.xxx",
    "test": "storage11FB-0B1CAndroiddataxx.xxx.xxx.xxx.xxx"
}

I also tried using a 1 line SQLBatch and it does the same thing, using the Batch method I added a debug statement into the execute method of SQLitePlugin.java as
Log.v("execute", actionAsString + ' ' + argsAsString);

Which returns:

fj:10;extra [1,2,"BEGIN",0,"insert or replace into settings(rowid, id, value) VALUES((SELECT rowid from settings WHERE id = ?), ?,?)",3,"data:storage","data:storage","{\"location\":\"SD0\",\"available\":3993202688,\"path\":\"\/storage\/emulated\/0\/Android\/data\/xx.xxx.xxx.xxx.xxx\",\"test\":\"\/storage\/11FB-0B1C\/Android\/data\/xx.xxx.xxx.xxx.xxx\"}","extra"]

So it would appear that the argsAtString arrives to the plugin source with an escaped string which I would have thought would have been fine. So I decided to cordova compile the app and insert the same log statement and it shows this:

fj:10;extra [1,2,"BEGIN",0,"insert or replace into settings(rowid, id, value) VALUES((SELECT rowid from settings WHERE id = ?), ?,?)",3,"data:storage","data:storage","{\"location\":\"SD1\",\"available\":484114432,\"path\":\"/storage/11FB-0B1C/Android/data/xx.xxx.xxx.xxx.xxx\",\"test\":\"/storage/11FB-0B1C/Android/data/xx.xxx.xxx.xxx.xxx\"}","extra"]

So the contents of the string are not escaped but the string quotes are.

A dirty fix would be:
Line 64 + argsAsString = argsAsString.replace("\\/", "/");
Not sure I would PR this as it should really identify the call is from Capacitor however there should not be any other instances of / within the argsAsString

Have sent you a pm but wanted to document this as it highlights the issue and I just want to check that will will not break anything else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants