starwing / lua-protobuf

A Lua module to work with Google protobuf
MIT License
1.71k stars 388 forks source link

fix(lpb_tointegerx): filter out illegal formats, such as, #a, #-aaa... #269

Closed zhoujiexiong closed 1 month ago

zhoujiexiong commented 1 month ago
local pb = require "pb"
local protoc = require "protoc"

assert(protoc:load [[
syntax = "proto3";
message Money {
  string currency = 1;
  repeated int64 values = 2;
}]])

local data = {
    currency = "MYR",
    values = {
    -- cases supported
    1, 2, -3, "#123", "0xabF", "#-0x123abcdef", "-#0x123abcdef", "#0x123abc", "123",
    -- cases filtered out
    --- "a", "+aaa", "#aaaaa",
    },
}

--pb.option "int64_as_string"
--pb.option "int64_as_hexstring"

local bytes = assert(pb.encode("Money", data))
print(pb.tohex(bytes))
print(ngx.encode_base64(bytes))

local data2 = assert(pb.decode("Money", bytes))
print(require "serpent".block(data2))
zhoujiexiong commented 1 month ago

ping @starwing

starwing commented 1 month ago

Good catch, thanks for contribution!

coveralls commented 1 month ago

Coverage Status

coverage: 99.611%. remained the same when pulling ad75e24f415cc061fb7ff6690bacda73af4d1e2b on zhoujiexiong:fix-lpb_tointegerx into 5e998726522725138fb4066f03a5cc478c7f7b2c on starwing:master.

zhoujiexiong commented 1 month ago

Hi @starwing ,

Would you please help release new version to luarocks? Thx.

starwing commented 1 month ago

@zhoujiexiong done