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

Update invokeRun*QueryRpc functions to support paths with special characters #7402

Merged
merged 15 commits into from
Dec 20, 2023

Conversation

MarkDuckworth
Copy link
Contributor

@MarkDuckworth MarkDuckworth commented Jun 28, 2023

getDocs(...) (lite API) and getCount(...) (lite API) and getCountFromServer(...) were returning incorrect data when the query path included special characters, like "+". This PR fixes that issue.

Fundamentally the issue is with special characters in the path segments when invoking RestConnection.invokeStreamingRPC(...). If these special characters are not escaped, then the server will interpret the path different from what the client intended.

For example, this unencoded path will not be treated by the server as expected by the client:
"projects/myproject/databases/(default)/documents/doc+with+plus/collection+with+plus/"

But if we encode the segments it will. This is how it would look encoded:
"projects/myproject/databases/(default)/documents/doc%2bwith%2bplus/collection%2bwith%2bplus/"

@MarkDuckworth MarkDuckworth requested review from a team as code owners June 28, 2023 20:13
@changeset-bot
Copy link

changeset-bot bot commented Jun 28, 2023

🦋 Changeset detected

Latest commit: 1ce5e4c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@firebase/firestore Patch
firebase Patch
@firebase/firestore-compat Patch

Not sure what this means? Click here to learn what changesets are.

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

@MarkDuckworth MarkDuckworth requested a review from a team as a code owner June 28, 2023 20:18
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 28, 2023

Size Report 1

Affected Products

  • @firebase/firestore

    TypeBase (15addde)Merge (408d19c)Diff
    browser374 kB375 kB+491 B (+0.1%)
    esm5360 kB360 kB+371 B (+0.1%)
    main576 kB577 kB+753 B (+0.1%)
    module374 kB375 kB+491 B (+0.1%)
    react-native375 kB375 kB+491 B (+0.1%)
  • @firebase/firestore-lite

    TypeBase (15addde)Merge (408d19c)Diff
    browser109 kB109 kB+385 B (+0.4%)
    esm5106 kB106 kB+327 B (+0.3%)
    main150 kB150 kB+624 B (+0.4%)
    module109 kB109 kB+385 B (+0.4%)
    react-native109 kB109 kB+385 B (+0.4%)
  • bundle

    13 size changes

    TypeBase (15addde)Merge (408d19c)Diff
    firestore (Persistence)302 kB302 kB+175 B (+0.1%)
    firestore (Query Cursors)238 kB238 kB+127 B (+0.1%)
    firestore (Query)236 kB236 kB+127 B (+0.1%)
    firestore (Read data once)224 kB224 kB+127 B (+0.1%)
    firestore (Read Write w Persistence)?321 kB? (?)
    firestore (Realtime updates)226 kB226 kB+127 B (+0.1%)
    firestore (Transaction)204 kB204 kB+128 B (+0.1%)
    firestore (Write data)204 kB204 kB+162 B (+0.1%)
    firestore-lite (Query Cursors)89.1 kB89.3 kB+209 B (+0.2%)
    firestore-lite (Query)85.3 kB85.5 kB+209 B (+0.2%)
    firestore-lite (Read data once)61.6 kB61.6 kB+56 B (+0.1%)
    firestore-lite (Transaction)86.4 kB86.6 kB+138 B (+0.2%)
    firestore-lite (Write data)71.1 kB71.2 kB+59 B (+0.1%)

  • firebase

    TypeBase (15addde)Merge (408d19c)Diff
    firebase-compat.js779 kB779 kB+318 B (+0.0%)
    firebase-firestore-compat.js340 kB341 kB+626 B (+0.2%)
    firebase-firestore-lite.js116 kB117 kB+385 B (+0.3%)
    firebase-firestore.js434 kB434 kB+491 B (+0.1%)

Test Logs

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

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 28, 2023

Size Analysis Report 1

This report is too large (359,718 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/Ye8XRsqKeU.html

Copy link
Contributor

@dconeybe dconeybe left a comment

Choose a reason for hiding this comment

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

I've left some comments and pushed up a commit with an alternate implementation. Let me know when you're ready to revisit this PR.

@dconeybe dconeybe assigned MarkDuckworth and unassigned dconeybe Jun 30, 2023
Copy link
Contributor

@egilmorez egilmorez left a comment

Choose a reason for hiding this comment

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

Is it true that the only doc string is in the .changeset file? LG there.

Please send Firestore doc string/doc impact reviews to markarndt@, thanks!

@dconeybe dconeybe removed their assignment Dec 19, 2023
* where each path segment has been encoded with
* `encodeURIComponent`.
*/
toUriEncodedString(): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, toUriEncodedString() shouldn't be on ResourcePath since it's an implementation detail specific to RestConnection, especially since it's only called once in the entire SDK. Consider moving this logic into RestConnection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered that, but I felt more strongly that the structure of the path and how to URI encode the path should be the responsibility of the Path class. IMO, the connection shouldn't be responsible for knowing how to break up a path and encode its parts.

Copy link
Contributor

@dconeybe dconeybe left a comment

Choose a reason for hiding this comment

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

Approved. Just left a thought about the new method added to ResourcePath.

@MarkDuckworth MarkDuckworth merged commit f478845 into master Dec 20, 2023
41 of 42 checks passed
@MarkDuckworth MarkDuckworth deleted the markduckworth/run-rpc-path-special-chars branch December 20, 2023 17:24
@google-oss-bot google-oss-bot mentioned this pull request Jan 16, 2024
@firebase firebase locked and limited conversation to collaborators Jan 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants