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

Escape regex tokens within field names #38

Merged
merged 6 commits into from
Nov 20, 2019
Merged

Escape regex tokens within field names #38

merged 6 commits into from
Nov 20, 2019

Conversation

PerfectPixel
Copy link
Contributor

Resolves #37

@erikras I just copied the suitable test-case and adjusted it to demonstrate the issue. Let me know if I should structure the tests differently. 👍

@codecov
Copy link

codecov bot commented Aug 9, 2019

Codecov Report

Merging #38 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #38   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          14     15    +1     
  Lines         157    159    +2     
  Branches       34     34           
=====================================
+ Hits          157    159    +2
Impacted Files Coverage Δ
src/utils.js 100% <100%> (ø)
src/removeBatch.js 100% <100%> (ø) ⬆️
src/pop.js 100% <100%> (ø) ⬆️
src/insert.js 100% <100%> (ø) ⬆️
src/remove.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7ee1ef8...a6cac96. Read the comment docs.

src/utils.js Outdated
@@ -0,0 +1,3 @@
// @flow
export const escapeRegexTokens = (str: string): string =>
str.replace(/([.\-[])/g, '\\$1')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found this robust regex on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping - maybe use this one with a comment where is it taken from?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'll change that.

@SpOOnman
Copy link
Contributor

This solution works for me too and I've suggested even more complex regex to improve this fix.

@erikras erikras merged commit 9f8f74f into final-form:master Nov 20, 2019
@erikras
Copy link
Member

erikras commented Nov 20, 2019

Published in v3.0.2.

@SpOOnman
Copy link
Contributor

Thanks @erikras !

@PerfectPixel PerfectPixel deleted the escape-all-the-regex branch November 20, 2019 13:28
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.

State-management on insert/... does not work on nested arrays
3 participants