Skip to content

Commit e4c8e35

Browse files
committed
Remove recursion in UnicodeNormalize.nfc_one, fixing bug 21159.
1 parent 83a943b commit e4c8e35

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/unicode_normalize/normalize.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,22 @@ def self.nfc_one(string)
111111
start = nfd_string[0]
112112
last_class = CLASS_TABLE[start]-1
113113
accents = ''
114+
result = ''
114115
nfd_string[1..-1].each_char do |accent|
115116
accent_class = CLASS_TABLE[accent]
116117
if last_class<accent_class and composite = COMPOSITION_TABLE[start+accent]
117118
start = composite
119+
elsif accent_class == 0
120+
result += start+accents
121+
start = accent
122+
accents = ''
123+
last_class = -1
118124
else
119125
accents << accent
120126
last_class = accent_class
121127
end
122128
end
123-
accents = nfc_one(accents) if accents.length>1 # TODO: change from recursion to loop
124-
hangul_comp_one(start+accents)
129+
hangul_comp_one(result+start+accents)
125130
end
126131

127132
def self.normalize(string, form = :nfc)

0 commit comments

Comments
 (0)