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

Fix invalid encoding name #575

Merged
merged 2 commits into from
Nov 2, 2024
Merged

Fix invalid encoding name #575

merged 2 commits into from
Nov 2, 2024

Conversation

miyucy
Copy link
Contributor

@miyucy miyucy commented Nov 2, 2024

Found an incorrect setting in the database encoding pragma that could potentially cause character encoding issues.

irb(main):012> a = SQLite3::Database.new(":memoery:")
=>
#<SQLite3::Database:0x000000011f6b5330
...
irb(main):013> a.encoding = "utf-16be "
/app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/statement.rb:36:in `prepare': unsupported encoding: UTF-16BE : (SQLite3::SQLException)
PRAGMA encoding='UTF-16BE '
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/statement.rb:36:in `initialize'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/database.rb:170:in `new'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/database.rb:170:in `prepare'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/database.rb:202:in `execute'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/pragmas.rb:65:in `set_enum_pragma'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/pragmas.rb:230:in `encoding='
        from (irb):13:in `<main>'
        from <internal:kernel>:187:in `loop'
        from <internal:prelude>:5:in `irb'
        from (app):16:in `<main>'
irb(main):014> a.encoding = "utf-16be"
/app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/pragmas.rb:63:in `set_enum_pragma': unrecognized encoding "utf-16be" (SQLite3::Exception)
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/pragmas.rb:230:in `encoding='
        from (irb):14:in `<main>'
        from <internal:kernel>:187:in `loop'
        from <internal:prelude>:5:in `irb'
        from (app):16:in `<main>'
irb(main):015> a.execute("pragma encoding='UTF-16BE '")
/app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/statement.rb:36:in `prepare': unsupported encoding: UTF-16BE : (SQLite3::SQLException)
pragma encoding='UTF-16BE '
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/statement.rb:36:in `initialize'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/database.rb:170:in `new'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/database.rb:170:in `prepare'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/database.rb:202:in `execute'
        from (irb):15:in `<main>'
        from <internal:kernel>:187:in `loop'
        from <internal:prelude>:5:in `irb'
        from (app):16:in `<main>'
irb(main):016> a.execute("pragma encoding='UTF-16BE'")
=> []

miyucy and others added 2 commits November 2, 2024 14:16
```
irb(main):012> a = SQLite3::Database.new(":memoery:")
=>
#<SQLite3::Database:0x000000011f6b5330
...
irb(main):013> a.encoding = "utf-16be "
/app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/statement.rb:36:in `prepare': unsupported encoding: UTF-16BE : (SQLite3::SQLException)
PRAGMA encoding='UTF-16BE '
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/statement.rb:36:in `initialize'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/database.rb:170:in `new'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/database.rb:170:in `prepare'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/database.rb:202:in `execute'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/pragmas.rb:65:in `set_enum_pragma'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/pragmas.rb:230:in `encoding='
        from (irb):13:in `<main>'
        from <internal:kernel>:187:in `loop'
        from <internal:prelude>:5:in `irb'
        from (app):16:in `<main>'
irb(main):014> a.encoding = "utf-16be"
/app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/pragmas.rb:63:in `set_enum_pragma': unrecognized encoding "utf-16be" (SQLite3::Exception)
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/pragmas.rb:230:in `encoding='
        from (irb):14:in `<main>'
        from <internal:kernel>:187:in `loop'
        from <internal:prelude>:5:in `irb'
        from (app):16:in `<main>'
irb(main):015> a.execute("pragma encoding='UTF-16BE '")
/app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/statement.rb:36:in `prepare': unsupported encoding: UTF-16BE : (SQLite3::SQLException)
pragma encoding='UTF-16BE '
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/statement.rb:36:in `initialize'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/database.rb:170:in `new'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/database.rb:170:in `prepare'
        from /app/vendor/bundle/ruby/3.3.0/gems/sqlite3-2.2.0-arm64-darwin/lib/sqlite3/database.rb:202:in `execute'
        from (irb):15:in `<main>'
        from <internal:kernel>:187:in `loop'
        from <internal:prelude>:5:in `irb'
        from (app):16:in `<main>'
irb(main):016> a.execute("pragma encoding='UTF-16BE'")
=> []
```
@flavorjones
Copy link
Member

@miyucy Thank you for this! It's been broken since #encoding= was introduced.

I added a commit with new test coverage for Database#encoding= and a changelog entry.

@flavorjones flavorjones merged commit ef13fcb into sparklemotion:main Nov 2, 2024
105 checks passed
@miyucy miyucy deleted the patch-1 branch November 3, 2024 04:36
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.

2 participants