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: RegExp "invalid group specifier name" exception on Safari < 16.4 #3564

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

wanderingmeow
Copy link
Contributor

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.

Before submitting, make sure you've checked the following:

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Have you written and run sufficient tests for validating the changes?
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Prefix: To cleary categorize this pull request, prefix the pull request title, using one of the following:
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

Description

This PR fixed the issue of regex exception for Safari before 16.4 (iOS 16.4), where regex lookbehind syntax is not supported. Before this change, devices that are not supported by or updated to iOS 16.4 or later are unable to use Open WebUI chat, e.g. iPhone 7.

Fixed


Additional Information

This issue was first observed in Open WebUI 0.3.5.

For more information, see discussion here: #3372 (comment)

Prior art:

@tjbck
Copy link
Contributor

tjbck commented Jul 1, 2024

Thanks!

@tjbck tjbck merged commit f3c1ff9 into open-webui:dev Jul 1, 2024
@tjbck
Copy link
Contributor

tjbck commented Jul 1, 2024

This change has been reverted in dev as this broke compatibility with OpenAI models. Feel free to reopen the PR again after THOROUGHLY testing the changes, thanks!

@wanderingmeow
Copy link
Contributor Author

Apologize for the oversight in my previous submission. It doesn't handle empty strings properly, which can occur quite often when token generation is slow.

Here's the updated one:

let sentences = text.match(/[^\.!\?] [\.!\?]*|. /g) || [];

I've tested it in both UI and browser console, and it works as expected. Here are the test results:

> let text = "Hello, there! What's this? This is a string."
> text.match(/[^\.!\?] [\.!\?]*|. /g) || [ "" ]
[ 'Hello, there!', " What's this?", ' This is a string.' ]
> text.split(/(?<=[.!?])\s /)
[ 'Hello, there!', "What's this?", 'This is a string.' ]
> text = ""
> text.match(/[^\.!\?] [\.!\?]*|. /g) || [ "" ]
[ '' ]
> text.split(/(?<=[.!?])\s /)
[ '' ]
> text = `Multiple
... lines.
... !`
> text.match(/[^\.!\?] [\.!\?]*|. /g) || [ "" ]
[ 'Multiple\nlines.', '\n!' ]
> text.split(/(?<=[.!?])\s /)
[ 'Multiple\nlines.', '!' ]

Even though leading whitespace characters exist, they will be trimmed later by sentence.trim().

As this PR has already been merged, I'm unable to reopen it. You could commit this directly. Thank you for your time.

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.

None yet

2 participants