镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Open
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
2 changes: 1 addition & 1 deletion ext/sqlite3/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ bind_param(VALUE self, VALUE key, VALUE value)
SQLITE_TRANSIENT
);
} else {
if (!UTF8_P(value) || !USASCII_P(value)) {
if (!UTF8_P(value)) {
value = rb_str_encode(value, rb_enc_from_encoding(rb_utf8_encoding()), 0, Qnil);
}
status = sqlite3_bind_text(
Expand Down
20 changes: 20 additions & 0 deletions test/test_statement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,26 @@ def test_bind_param_string
stmt.close
end

def test_bind_invalid_utf8_as_text
["\xff", "\xe2\x82"].each do |value|
@db.prepare("select typeof(?), ?") do |stmt|
stmt.bind_params(value, value)
type, text = stmt.step
assert_equal "text", type
assert_equal value.bytes, text.bytes
assert_equal Encoding::UTF_8, text.encoding
end
end
end

def test_bind_invalid_us_ascii_text_raises
@db.prepare("select ?") do |stmt|
assert_raises(Encoding::InvalidByteSequenceError) do
stmt.bind_param(1, "\xff".b.force_encoding(Encoding::US_ASCII))
end
end
end

def test_bind_param_int
stmt = SQLite3::Statement.new(@db, "select ?")
stmt.bind_param(1, 10)
Expand Down
Loading