Fix: Enums with spaces are not converted properly#5276
Fix: Enums with spaces are not converted properly#5276duckies wants to merge 6 commits intotypeorm:masterfrom
Conversation
Signed-off-by: duckies <[email protected]>
|
My team just ran into this issue. It's a pretty crucial bug, would be really nice to see this fixed. Our product does hotel bookings, and this caused some serious issues for us. |
| // Remove extraneous delimiting quotes around enum strings with spaces. | ||
| value = value.map((val: string) => { | ||
| // Returns an empty string if the length is negative. | ||
| const stripped = val.substr(1, val.length - 2); |
There was a problem hiding this comment.
This code isn't obvious to me. As I understood you are trying to remove quotes around enum strings by this code. But what if there are no quotes around? Wouldn't it remove regular characters from it?
|
We are facing the same issue. And waiting this fix to be included into main branch. Thanks. |
| @@ -0,0 +1,44 @@ | |||
| import "reflect-metadata"; | |||
| import { Connection } from "../../../src"; | |||
There was a problem hiding this comment.
This entire test file needs to be in the correct directory
| describe("github issues > #5275 Enums with spaces are not converted properly.", () => { | ||
| let connections: Connection[]; | ||
| before(async () => connections = await createTestingConnections({ | ||
| entities: [__dirname + "/entity/*{.js,.ts}"], |
There was a problem hiding this comment.
Just pass the entities in directly
| // Remove extraneous delimiting quotes around enum strings with spaces. | ||
| value = value.map((val: string) => { | ||
| // Returns an empty string if the length is negative. | ||
| const stripped = val.substr(1, val.length - 2); |
|
I personally no longer use TypeORM, so if a more generalized solution is desired feel free to close this. |
Postgres returns values for enum arrays in formats like
{"Guild Master", Recruit}and are incorrectly converted to['"Guild Master"', 'Recruit' ].Potential issues arise depending on the fix implementation if the user wanted quotes in their enum. I utilized a dirty patch that removes the first and last characters from the string and determines if it's a valid enum.