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 Facet Parsing #116

Merged
merged 2 commits into from
Dec 6, 2024
Merged

Fix Facet Parsing #116

merged 2 commits into from
Dec 6, 2024

Conversation

drasticactions
Copy link
Owner

@drasticactions drasticactions commented Dec 6, 2024

In the documentation, I had wrote that you need to get the byte slice to create a facet. For example:

// To insert a link, we need to find the start and end of the link text.
// This is done as a "ByteSlice."
int promptStart = prompt.IndexOf("Link Goes Here!", StringComparison.InvariantCulture);
int promptEnd = promptStart + Encoding.Default.GetBytes("Link Goes Here!").Length;
var index = new FacetIndex(promptStart, promptEnd);
var link = FacetFeature.CreateLink("https://drasticactions.dev");
var facet = new Facet(index, link);

This is "kinda" right (You do need to get the bytes from UTF8, not rely on the default from .NET, and the start index may not represent the actual place in the byte array), but not only is this not totally correct, the helpers I wrote to make them were not using this. They were using Length from the matched Regex. This would break with Unicode/non-ASCII characters.

This should fix it by using spans to pattern match.

To use the new helpers, you can use Facet.Parse for a complete string, or Facet.ForMentions, Facet.ForHashtags, Facet.ForMentions for the individual facets.

@drasticactions drasticactions merged commit 1e41bca into develop Dec 6, 2024
3 checks passed
@drasticactions drasticactions deleted the fix-facets branch December 6, 2024 13:36
drasticactions added a commit that referenced this pull request Dec 27, 2024
* Add missing parameters to getAuthorFeed

* Don't set ATError object when logging

* Add AspectRatio to ImageView

* Start sourcegen

* Update

* Update Tools

* Update

* Remove usings, since it's in global

* Try again

* update

* Update

* Update

* Update

* Update

* Update

* Update

* Almost...

* Update

* Update

* Update logging-in.md

* Add codeflow to readme

* Update...

* Expose the Cursor on the NotificationCollection

* Almost... maybe...

* Firehose

* Update

* The big one

* Update

* Update...

* Fix Readme

* Start refactoring...

* More types

* More cleanup

* More modding...

* More types...

* Closer...

* Nearly...

* Fun!

* First run!

* Tests and More

* Add Tests for Endpoints

* Add class entries

* Trying to generate helpers...

* More generated Parameters

* And helper methods!

* Update Generated Types with less aggressive Null values

Also fix JSON ATObject type to allow fallback

* Update Docs, bump ATProto again...

* Revert...

* Revert...

* Revert...

* Add parameter constructors...

* Update docs

* More docs

* Update docs

* Adjust tests (???)

* Remove deprecated classes and methods

* Remove FishyFlipDX, Replace FishyFlip with Source Gen Bits (#104)

+semver: breaking

* Add docs, bump to net9.0 (#105)

* Add docs, bump to net9.0

* Bump to net9

* Fix ImportRepo, add OpenGraphParser (#106)

* Fix ImportRepo

* Add OpenGraphParser

* Cleanup + Fix WASM support  (#108)

* Order by classname

* Update

* small cleanup

* Update

* Use SupportsAutomaticDecompression for setting AutomaticDecompression, add WASM site back

* Add WhiteWind Generator, add GetRecord (#110)

* Add ATError Object Generator (#112)

* Add Error Generator

* Add Possible Errors

* Warning cleanup

* Add ToString override for ATError (#113)

* Fix GetBlob to return byte[] (#114)

* Resolve Repo DIDs and Handles independently (#115)

* Start refactoring URL

* Update

* Fix tests

* Fix Facet Parsing (#116)

* Fix Facet Parsing

* Remove DistinctBy

* Reintroduce bskycli (#117)

* Add bskycli

* Image Aspect Ratio

* Update

* Update

* Update readme

* Update

* Fix Windows script

* Bump ATProtocol, Bind ATFile Lexicon support (#118)

* Bump atprotocol

* Add ATFile support

* Add build_binding script (#119)

* Update PasswordAuth with AuthenticateWithPasswordResultAsync (#120)

* Update PasswordAuth with AuthenticateWithPasswordResultAsync

* Really???

* Use public.api.bsky.app for unauthed sessions by default (#121)

* Add 2FA Auth Token support for Password Auth (#122)

* Bump dependencies (#123)

* Add Post helper for PostView (#124)

* Bump dependencies (#125)

* Resolve users PDS before authentication (#126)

* Add Pastesphere support (#127)

* Add AniBlue support (#128)

* Bump Bindings (#129)

* Add community lexicons (#130)

* Add DidDoc helpers (#131)

* patch: Special case booleans (#132)

* Bump bindings (#133)

* Override ATUri/ATIdentifier Equals for proper checking (#134)

* Bump bindings

* Override Equals

* Add support for setting Labels / Fixes Chat (#135)

* Update SourceGen for Labels

* Update for labels

* Fix chat too

---------

Co-authored-by: Thomas May <[email protected]>
Co-authored-by: Kevin Gosse <[email protected]>
Co-authored-by: Matt Brailsford <[email protected]>
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.

1 participant