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

UserAgent regex broken in ScalaJS #2707

Closed
swoogles opened this issue Feb 27, 2024 · 13 comments
Closed

UserAgent regex broken in ScalaJS #2707

swoogles opened this issue Feb 27, 2024 · 13 comments
Labels
💎 Bounty bug Something isn't working 💰 Rewarded

Comments

@swoogles
Copy link
Contributor

Describe the bug

This blows up when its referenced in the browser.

private val completeRegex = s"""^(?i)([a-z0-9]+)(?:/([a-z0-9.]+))(.*)$$""".r

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 swoogles added the bug Something isn't working label Feb 27, 2024
@987Nabil
Copy link
Contributor

987Nabil commented Mar 1, 2024

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

@jamesward
Copy link
Contributor

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.

@987Nabil
Copy link
Contributor

987Nabil commented Mar 2, 2024

@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

@jamesward
Copy link
Contributor

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.

@swoogles
Copy link
Contributor Author

swoogles commented Mar 2, 2024

Related (Almost decade-old) thread-
scala-js/scala-js#997 (comment)

@987Nabil
Copy link
Contributor

987Nabil commented Mar 3, 2024

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

@russwyte
Copy link
Contributor

russwyte commented Mar 4, 2024

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

@987Nabil
Copy link
Contributor

987Nabil commented Mar 5, 2024

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

@jdegoes
Copy link
Member

jdegoes commented Jun 5, 2024

/bounty $250

Copy link

algora-pbc bot commented Jun 5, 2024

## 💎 $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

@pablf
Copy link
Member

pablf commented Jun 15, 2024

/attempt #2707

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

Copy link

algora-pbc bot commented Jun 15, 2024

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

Copy link

algora-pbc bot commented Jun 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 Bounty bug Something isn't working 💰 Rewarded
Projects
None yet
Development

No branches or pull requests

6 participants