zio-http icon indicating copy to clipboard operation
zio-http copied to clipboard

UserAgent regex broken in ScalaJS

Open swoogles opened this issue 11 months ago • 8 comments

Describe the bug

This blows up when its referenced in the browser.

https://github.com/zio/zio-http/blob/28c9de1d09b9d8da903dd80edda4a5c4277a5b88/zio-http/shared/src/main/scala/zio/http/Header.scala#L4151

To Reproduce On snapshot - 3.0.0-RC4+77-66867e7f-SNAPSHOT/

object Main extends ZIOAppDefault{
  def run =
    ZIO.succeed(Header.UserAgent)
}
Screenshot 2024-02-27 at 4 40 59 PM

swoogles avatar Feb 27 '24 23:02 swoogles

Is this actually a zio http error? It seems like valid scala code is producing invalid js code. Is this a scalajs bug?

987Nabil avatar Mar 01 '24 13:03 987Nabil

Regex's that are used in both JS and the JVM, must be compatible with both. No way around there being two different Regex engines.

jamesward avatar Mar 01 '24 13:03 jamesward

@jamesward that's my point. I as a lib dev should not make sure that my regex works for both. That should be the scala js compiler/transpiler

987Nabil avatar Mar 02 '24 12:03 987Nabil

I agree. But unfortunately I don't think Scala has any plans to write their own Regex engine. So the reality for now is that users have to write Regex that works on their target platforms.

jamesward avatar Mar 02 '24 13:03 jamesward

Related (Almost decade-old) thread- https://github.com/scala-js/scala-js/issues/997#issuecomment-54197139

swoogles avatar Mar 02 '24 14:03 swoogles

Okay 🙄 At least the issue is clear now.

One way around would be to not use regex at all for the header parsing but RichTextCodec

987Nabil avatar Mar 03 '24 10:03 987Nabil

Would zio-parser be a viable option? One possible win would be that it is invertible.

russwyte avatar Mar 04 '24 13:03 russwyte

RichTextCodec is similar to zio parser and we would not have another dependency.

987Nabil avatar Mar 05 '24 07:03 987Nabil

/bounty $250

jdegoes avatar Jun 05 '24 02:06 jdegoes

~~## 💎 $250 bounty • ZIO~~

~~### Steps to solve:~~ ~~1. Start working: Comment /attempt #2707 with your implementation plan~~ ~~2. Submit work: Create a pull request including /claim #2707 in the PR body to claim the bounty~~ ~~3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts~~

~~### Additional opportunities:~~ ~~* 🔴 Livestream on Algora TV while solving this bounty & earn $200 upon merge! Make sure to have your camera and microphone on. Comment /livestream once live~~

~~Thank you for contributing to zio/zio-http!~~

~~Add a bountyShare on socials~~

Attempt Started (GMT+0) Solution
🟢 @pablf Jun 15, 2024, 12:24:20 AM #2912

algora-pbc[bot] avatar Jun 05 '24 02:06 algora-pbc[bot]

/attempt #2707

Algora profile Completed bounties Tech Active attempts Options
@pablf    24 ZIO bounties
+ 1 bounty from 1 project
Scala, Rust
Cancel attempt

pablf avatar Jun 15 '24 00:06 pablf

💡 @pablf submitted a pull request that claims the bounty. You can visit your bounty board to reward.

algora-pbc[bot] avatar Jun 15 '24 08:06 algora-pbc[bot]

🎉🎈 @pablf has been awarded $250! 🎈🎊

algora-pbc[bot] avatar Jun 18 '24 12:06 algora-pbc[bot]