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

FIX: sort strings in UTF-8 encoded byte order #8691

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

milaGGL
Copy link
Contributor

@milaGGL milaGGL commented Jan 6, 2025

Strings should be sorted in UTF-8 encoded byte order. Public document: https://cloud.google.com/firestore/docs/concepts/data-types#data_types

SDK sorts strings using built in comparator method, which sorts lexicographically, and leads to mismatch between server and sdk when special characters are present. This PR fixes the string order mismatches on document field, map key, and document key.

Remaining bug: when document keys include special characters, reading docs from IndexedDB with order fields (other than document ID) will miss some documents as indexedDB uses lexicographical order.

Copy link

changeset-bot bot commented Jan 6, 2025

⚠️ No Changeset found

Latest commit: 7de7220

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jan 6, 2025

Size Report 1

Affected Products

  • @firebase/app-check

    TypeBase (32bf021)Merge (e2d5d6e)Diff
    browser26.3 kB26.3 kB+4 B (+0.0%)
    main27.3 kB27.3 kB+6 B (+0.0%)
    module26.3 kB26.3 kB+4 B (+0.0%)
  • @firebase/data-connect

    TypeBase (32bf021)Merge (e2d5d6e)Diff
    browser20.2 kB20.1 kB-125 B (-0.6%)
    main22.1 kB22.0 kB-125 B (-0.6%)
    module20.2 kB20.1 kB-125 B (-0.6%)
  • @firebase/firestore

    TypeBase (32bf021)Merge (e2d5d6e)Diff
    browser382 kB382 kB+316 B (+0.1%)
    main589 kB589 kB+374 B (+0.1%)
    module382 kB382 kB+316 B (+0.1%)
    react-native382 kB382 kB+316 B (+0.1%)
  • @firebase/firestore-lite

    TypeBase (32bf021)Merge (e2d5d6e)Diff
    browser111 kB112 kB+316 B (+0.3%)
    main154 kB154 kB+374 B (+0.2%)
    module111 kB112 kB+316 B (+0.3%)
    react-native112 kB112 kB+316 B (+0.3%)
  • @firebase/remote-config

    TypeBase (32bf021)Merge (e2d5d6e)Diff
    browser19.2 kB21.7 kB+2.56 kB (+13.3%)
    main20.2 kB22.9 kB+2.65 kB (+13.1%)
    module19.2 kB21.7 kB+2.56 kB (+13.3%)
  • @firebase/util

    TypeBase (32bf021)Merge (e2d5d6e)Diff
    browser23.4 kB23.2 kB-168 B (-0.7%)
    main29.2 kB29.0 kB-222 B (-0.8%)
    module23.4 kB23.2 kB-168 B (-0.7%)
  • bundle

    19 size changes

    TypeBase (32bf021)Merge (e2d5d6e)Diff
    app-check (CustomProvider)37.5 kB37.3 kB-142 B (-0.4%)
    app-check (ReCaptchaEnterpriseProvider)40.0 kB39.8 kB-144 B (-0.4%)
    app-check (ReCaptchaV3Provider)39.9 kB39.8 kB-144 B (-0.4%)
    firestore (CSI Auto Indexing Disable and Delete)272 kB273 kB+185 B (+0.1%)
    firestore (CSI Auto Indexing Enable)272 kB273 kB+185 B (+0.1%)
    firestore (Persistence)304 kB304 kB+185 B (+0.1%)
    firestore (Query Cursors)249 kB249 kB+185 B (+0.1%)
    firestore (Query)247 kB247 kB+185 B (+0.1%)
    firestore (Read data once)235 kB235 kB+185 B (+0.1%)
    firestore (Read Write w Persistence)328 kB329 kB+185 B (+0.1%)
    firestore (Realtime updates)237 kB237 kB+185 B (+0.1%)
    firestore (Transaction)214 kB214 kB+185 B (+0.1%)
    firestore (Write data)213 kB214 kB+185 B (+0.1%)
    firestore-lite (Query Cursors)103 kB103 kB+185 B (+0.2%)
    firestore-lite (Query)98.8 kB99.0 kB+185 B (+0.2%)
    firestore-lite (Read data once)74.3 kB74.5 kB+185 B (+0.2%)
    firestore-lite (Transaction)99.5 kB99.7 kB+185 B (+0.2%)
    firestore-lite (Write data)83.9 kB84.1 kB+185 B (+0.2%)
    remote-config (getAndFetch)46.3 kB47.5 kB+1.20 kB (+2.6%)

  • firebase

    TypeBase (32bf021)Merge (e2d5d6e)Diff
    firebase-app-check-compat.js23.4 kB23.2 kB-136 B (-0.6%)
    firebase-app-check.js25.0 kB24.9 kB-107 B (-0.4%)
    firebase-compat.js797 kB799 kB+1.18 kB (+0.1%)
    firebase-data-connect.js16.7 kB16.7 kB-89 B (-0.5%)
    firebase-firestore-compat.js347 kB347 kB+185 B (+0.1%)
    firebase-firestore-lite.js130 kB130 kB+316 B (+0.2%)
    firebase-firestore.js441 kB441 kB+316 B (+0.1%)
    firebase-remote-config-compat.js27.3 kB28.4 kB+1.13 kB (+4.1%)
    firebase-remote-config.js29.6 kB31.3 kB+1.69 kB (+5.7%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/v4PfLrVlJq.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jan 6, 2025

Size Analysis Report 1

This report is too large (508,382 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/9cFn5TaQq9.html

@milaGGL milaGGL changed the title add a test sort strings in UTF-8 encoded byte order Jan 6, 2025
@@ -74,6 +74,22 @@ export interface Equatable<T> {
isEqual(other: T): boolean;
}

/** Compare strings in UTF-8 encoded byte order */
export function compareUtf8Strings(left: string, right: string): number {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comparison function added here to avoid circular dependency.

@milaGGL milaGGL marked this pull request as ready for review January 10, 2025 21:51
@milaGGL milaGGL requested review from a team as code owners January 10, 2025 21:51
@DellaBitta
Copy link
Contributor

For PRs, please add information to the PR summary as to why this change is being made including any internal b/ tickets or any external GH issues that are associated with it so, later, if something goes wrong, we can reference the information. Also could you add a patch-level changeset since this a behavioral change?

@milaGGL milaGGL changed the title sort strings in UTF-8 encoded byte order FIX: sort strings in UTF-8 encoded byte order Jan 13, 2025
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

Successfully merging this pull request may close these issues.

3 participants