-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
sqlite date hydration is susceptible to corruption #3949
Comments
@jacobg Why don't you make a PR with such changes? We will see if such approach doesn't break any tests etc. |
Thanks @Kononnable. I'm working on that. I'm trying to write a unit test for it, but when I call |
I don't have a clue why it would behave like that. Push changes to your fork or add a PR with an annotation that it didn't compiled as expected and we will see what we can do. Without access to the code it will be difficult to determine what's wrong. |
Hi @Kononnable, Here's my fork: It has the unit test, but it doesn't have the fix yet, but I need to get the unit test running first. I just cloned the repo, and ran:
But it ignores my unit test, and it's not under Thanks! |
Haha. I accidentally added a space to the end of the filename, and so |
@Kononnable |
sqlite date hydration is susceptible to corruption #3949
Issue type:
[ ] question
[X] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[X]
cordova
[ ]
mongodb
[ ]
mssql
[ ]
mysql
/mariadb
[ ]
oracle
[ ]
postgres
[ ]
cockroachdb
[X]
sqlite
[ ]
sqljs
[ ]
react-native
[ ]
expo
TypeORM version:
[X]
latest
[ ]
@next
[ ]
0.x.x
(or put your version here)Steps to reproduce or a small repository showing the problem:
The AbstractSqliteDriver.prepareHydratedValue function contains this code:
This code works fine if the datetime text stored in sqlite is of the format
"2018-03-14 02:33:33.906"
. But sqlite also supports storing datetime strings in ISO 8601 format"2018-03-14T02:33:33.906Z"
. So if it's already stored in sqlite in ISO 8601 format, then typeorm will change the string to"2018-03-14T02:33:33.906ZZ"
, i.e., twoZ
s the end. Or alternatively, it would change"2018-03-14T02:33:33.906+00:00"
to"2018-03-14T02:33:33.906+00:00Z"
, which is also invalid. The result is that typeorm will call the Date constructor on the invalid date string, and the Date object will also be an invalid date when the entity class is instantiated.The reason this code normally works fine is that if the database row was saved using typeorm, then typeorm will save the date in the expected format. But if the database row was already created outside typeorm, then it is valid to save a sqlite database row in that ISO 8601 format. So because it's valid sqlite datetime format, typeorm should also support it.
I think the correct solution would be to only change the date string if the date string format exactly matches what is expected, i.e., a regex like
/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\.\d\d\d/
.The text was updated successfully, but these errors were encountered: