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

This page crashed - URI malformed - When inserting win10 keyboard emoji on api field #260

Closed
jNullj opened this issue Sep 6, 2023 · 6 comments · Fixed by #261
Closed

Comments

@jNullj
Copy link
Contributor

jNullj commented Sep 6, 2023

This was first detected in badges/shields#9519, Read more there
I can reproduce this on docusaurus-openapi.netlify.app

  1. Go to https://docusaurus-openapi.netlify.app/petstore/get-user-by-user-name/
  2. Select the username text input field
  3. Open win10 on screen keyboard (the one that pop-ups from bellow, not the old win7 version)
  4. Select an emoji
  5. Get page crash with URI malformed
@jNullj
Copy link
Contributor Author

jNullj commented Sep 6, 2023

More findings:
I see a diff with events data when using windows on-screen keyboard and emoji shortcut (winkey+.)
With on-screen keyboard when the issue appears:
image
With the emoji picker (win+.) when there is no issue:
image

@jNullj
Copy link
Contributor Author

jNullj commented Sep 6, 2023

Found the bug!
image
We are using encodeURIComponent to convert to a URI in the api call, but encodeURIComponent does not work with the unicode format '\uD83C' that the keyboard outputs insted of the emoji itself.

This can be found in https://github.com/cloud-annotations/docusaurus-openapi/blob/main/packages/docusaurus-theme-openapi/src/theme/ApiDemoPanel/buildPostmanRequest.ts

I can make a pull request fixing this

@jNullj
Copy link
Contributor Author

jNullj commented Sep 6, 2023

Was too quick, this is not a valid unicode, i need to keep debugging

@jNullj
Copy link
Contributor Author

jNullj commented Sep 6, 2023

Ok new insight, this is probebly related to onInput event.
It appears that when i type using onInput the emoji start as non-exitsting unicode like \uD83C then the input continues and completes it into the pizza emoji.
But our code tries to use encodeURIComponent in this middle state where only partial emoji was registered by onInput

@jNullj
Copy link
Contributor Author

jNullj commented Sep 6, 2023

Confirmed using this textbox on github. I asked it to print to console the onInput event and from 1 emoji input using the keyboard i get 2 onInput events
image

Ok you learn something new everyday, those are UTF-16 Encoding for emoji

So i get that the onInput meets half an emoji from the UTF-16 emoji and sends it to encodeURIComponent which fails

Will PR today or tomorrow with a solution

@bourdakos1
Copy link
Member

Good find! Thanks for looking into this :)

jNullj added a commit to jNullj/docusaurus-openapi that referenced this issue Sep 7, 2023
This commit fixes an issue where utf-16 encoded surrogated pair could crash the page when inserted as input.
The commit adds endsWithHalfSurrogatePair to check for half pair and safeEncodeURIComponent to ignore half surrogated pair before passing it to encodeURIComponent.

Fixes cloud-annotations#260
bourdakos1 pushed a commit that referenced this issue Nov 4, 2023
This commit fixes an issue where utf-16 encoded surrogated pair could crash the page when inserted as input.
The commit adds endsWithHalfSurrogatePair to check for half pair and safeEncodeURIComponent to ignore half surrogated pair before passing it to encodeURIComponent.

Fixes #260
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 a pull request may close this issue.

2 participants