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

replace half diacritics U+FE20, U+FE21 with correct diacritic U+0361 #1375

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/traject/readers/folio_postgres_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def each
break if response.nil?

response.each do |row|
data = JSON.parse(row['jsonb_build_object'])
jsonb_build_object = Traject::FolioPostgresReader.encoding_cleanup(row['jsonb_build_object'])
data = JSON.parse(jsonb_build_object)

merge_separately_queried_data!(data)

Expand All @@ -73,6 +74,11 @@ def each
end
end

def self.encoding_cleanup(row)
# cleans up cyrlic encoding i︠a︡ to i͡a
row.gsub(/[?=\ufe20](.{1,2})[?<=\ufe21]/, "\u0361\\1")
end

def sql_server_current_time
Time.parse(@connection.exec('SELECT NOW()').getvalue(0, 0))
end
Expand Down
21 changes: 21 additions & 0 deletions spec/lib/traject/readers/folio_postgres_reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,25 @@
expect(result).to be_a FolioRecord
end
end

context 'check encoding parsing' do
encoding_sample_str_json = JSON.generate({ 'title1' => 'Strategii︠a︡ planirovanii︠a︡ izbiratelʹnoĭ kampanii',
'title2' => 'Unencoded string',
'title3' => 'Strategiii︠a planirovaniia︡ izbiratelʹnoĭ kampanii' })
let(:encoded_string) do
JSON.parse(described_class.encoding_cleanup(encoding_sample_str_json))
end

it 'encodes cyrilic correctly' do
expect(encoded_string['title1']).to eq('Strategii͡a planirovanii͡a izbiratelʹnoĭ kampanii')
end

it 'returns unencoded string without change' do
expect(encoded_string['title2']).to eq('Unencoded string')
end

it 'returns encoded string without change' do
expect(encoded_string['title3']).to eq('Strategiii︠a planirovaniia︡ izbiratelʹnoĭ kampanii')
end
end
end
Loading