File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
packages/convex-helpers/server Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -1822,21 +1822,35 @@ function compareKeys(key1: Key, key2: Key): number {
1822
1822
function serializeCursor ( key : IndexKey ) : string {
1823
1823
return JSON . stringify (
1824
1824
convexToJson (
1825
- key . map ( ( v ) : Value => ( v === undefined ? { $undefined : true } : v ) ) ,
1825
+ key . map (
1826
+ ( v ) : Value =>
1827
+ v === undefined
1828
+ ? "$_"
1829
+ : typeof v === "string" && v . endsWith ( "$_" )
1830
+ ? // in the unlikely case their string was "$_" or "$$_" etc.
1831
+ // we need to escape it. Always add a $ so "$$_" becomes "$$$_"
1832
+ "$" + v
1833
+ : v ,
1834
+ ) ,
1826
1835
) ,
1827
1836
) ;
1828
1837
}
1829
1838
1830
1839
function deserializeCursor ( cursor : string ) : IndexKey {
1831
1840
return ( jsonToConvex ( JSON . parse ( cursor ) ) as Value [ ] ) . map ( ( v ) => {
1832
- if ( typeof v === "object" && ! Array . isArray ( v ) && v !== null ) {
1833
- const entries = Object . entries ( v ) ;
1834
- if ( entries . length === 1 && entries [ 0 ] ! [ 0 ] === "$undefined" ) {
1841
+ if ( typeof v === "string" ) {
1842
+ if ( v === "$_" ) {
1835
1843
// This is a special case for the undefined value.
1836
1844
// It's not a valid value in the index, but it's a valid value in the
1837
1845
// cursor.
1838
1846
return undefined ;
1839
1847
}
1848
+ if ( v . endsWith ( "$_" ) ) {
1849
+ // in the unlikely case their string was "$_" it was changed to "$$_"
1850
+ // in the serialization process. If it was "$$_", it was changed to
1851
+ // "$$$_" and so on.
1852
+ return v . slice ( 1 ) ;
1853
+ }
1840
1854
}
1841
1855
return v ;
1842
1856
} ) ;
You can’t perform that action at this time.
0 commit comments