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 @@ -1851,21 +1851,35 @@ function compareKeys(key1: Key, key2: Key): number {
1851
1851
function serializeCursor ( key : IndexKey ) : string {
1852
1852
return JSON . stringify (
1853
1853
convexToJson (
1854
- key . map ( ( v ) : Value => ( v === undefined ? { $undefined : true } : v ) ) ,
1854
+ key . map (
1855
+ ( v ) : Value =>
1856
+ v === undefined
1857
+ ? "$_"
1858
+ : typeof v === "string" && v . endsWith ( "$_" )
1859
+ ? // in the unlikely case their string was "$_" or "$$_" etc.
1860
+ // we need to escape it. Always add a $ so "$$_" becomes "$$$_"
1861
+ "$" + v
1862
+ : v ,
1863
+ ) ,
1855
1864
) ,
1856
1865
) ;
1857
1866
}
1858
1867
1859
1868
function deserializeCursor ( cursor : string ) : IndexKey {
1860
1869
return ( jsonToConvex ( JSON . parse ( cursor ) ) as Value [ ] ) . map ( ( v ) => {
1861
- if ( typeof v === "object" && ! Array . isArray ( v ) && v !== null ) {
1862
- const entries = Object . entries ( v ) ;
1863
- if ( entries . length === 1 && entries [ 0 ] ! [ 0 ] === "$undefined" ) {
1870
+ if ( typeof v === "string" ) {
1871
+ if ( v === "$_" ) {
1864
1872
// This is a special case for the undefined value.
1865
1873
// It's not a valid value in the index, but it's a valid value in the
1866
1874
// cursor.
1867
1875
return undefined ;
1868
1876
}
1877
+ if ( v . endsWith ( "$_" ) ) {
1878
+ // in the unlikely case their string was "$_" it was changed to "$$_"
1879
+ // in the serialization process. If it was "$$_", it was changed to
1880
+ // "$$$_" and so on.
1881
+ return v . slice ( 1 ) ;
1882
+ }
1869
1883
}
1870
1884
return v ;
1871
1885
} ) ;
You can’t perform that action at this time.
0 commit comments