web-ridge / react-native-paper-dates

Smooth and fast cross platform Material Design date and time picker for React Native Paper
https://www.reactnativepaperdates.com
MIT License
638 stars 162 forks source link

Fix for passing dot as splitcharacter to RegExp constructor #297

Closed pragatheeswarans closed 1 year ago

pragatheeswarans commented 1 year ago

Issue:

When the locale of the DatePickerInput component is set to "de" (German), the functionality to add an automatic date separator ("." in the case of the German locale) is broken. Instead of appending a dot to the first two characters entered, the input gets changed to a single dot. Subsequently, any numbers entered are concatenated without the proper separator.

Solution:

I found the usage of the RegExp constructor to create regular expressions. One of the supported date separator is . (dd.mm.yyyy). The dot character is a metacharacter in regular expressions which needs to be escaped if it is being passed into the RegExp constructor. In this code block, it was not escaped. Hence the code

new RegExp('.', 'g')

yielded a different regex than the expected one.

Fixes DatePickerInput component breaks automatic date separator when setting locale to "de"

RichardLindhout commented 1 year ago

@pragatheeswarans I'm don't fully understand of what is going on but LGTM!