Skip to content

Fix key splitting failures if key contains any parenthesis char#550

Merged
glebm merged 1 commit intoglebm:mainfrom
bookingexperts:forked-repo-fix-key-splitting-errors
Feb 17, 2024
Merged

Fix key splitting failures if key contains any parenthesis char#550
glebm merged 1 commit intoglebm:mainfrom
bookingexperts:forked-repo-fix-key-splitting-errors

Conversation

@tom-brouwer-bex
Copy link
Copy Markdown
Contributor

Note that the complete split_key function has been refactored to be more readable, and a test has been added to check for the failures that occurred previously

Closes #549

@tom-brouwer-bex tom-brouwer-bex force-pushed the forked-repo-fix-key-splitting-errors branch from ed821c8 to 0fdc73f Compare February 15, 2024 16:11
For example, if a key contains a '>' or ')' char, but these are
not preceded by an opening character, everything after this
character was previously considered to be inside parenthesis.

This update ensures dots are only escaped if chars are both
preceded by parenthesis opening characters, and followed by closing
characters
@tom-brouwer-bex tom-brouwer-bex force-pushed the forked-repo-fix-key-splitting-errors branch from 0fdc73f to 61bc4fc Compare February 16, 2024 07:57
if parts.length + 1 >= max
parts << key[pos..] unless pos == key.length
break
parts = []
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This does a lot more allocations than the previous version.
split_key is called a lot, what's the impact on performance?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's actually faster on my machine (M1 Macbook Air):

On commit 0b4b483c82664f26c5696fb0f6aa1297356e4683 (latest main):

> Benchmark.measure { 1_000_000.times do ; I18n::Tasks::SplitKey.split_key('a.#{b.c}.d.<e.f>'); end }
#<Benchmark::Tms:0x0000000105396880 @cstime=0.0, @cutime=0.0, @label="", @real=4.406474999999773, @stime=0.005112000000000005, @total=4.400721000000001, @utime=4.395609>

On commit 61bc4fc4c25632798401599f6be6b7a45fef9945 (this PR):

> Benchmark.measure { 1_000_000.times do ; I18n::Tasks::SplitKey.split_key('a.#{b.c}.d.<e.f>'); end }
#<Benchmark::Tms:0x0000000103042190 @cstime=0.0, @cutime=0.0, @label="", @real=3.340463999998974, @stime=0.005928000000000003, @total=3.336179, @utime=3.330251>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Nice!

@glebm glebm merged commit 1ab60ab into glebm:main Feb 17, 2024
@tom-brouwer-bex tom-brouwer-bex deleted the forked-repo-fix-key-splitting-errors branch July 9, 2024 07:57
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.

Bug: Missing key checks and normalization fail if keys contain single parenthesis characters

2 participants