diff options
| author | Sergei Golubchik <serg@mariadb.org> | 2021-09-05 10:18:24 +0200 |
|---|---|---|
| committer | Sergei Golubchik <serg@mariadb.org> | 2021-10-12 13:28:10 +0200 |
| commit | 519bb2e41cee2d76826ae29d43c13941ebcf82c4 (patch) | |
| tree | 8747a31ec72f6ee0632e0d36af2076fb2384b985 | |
| parent | a363ccd6811458e0b8d0be113b08efc11b9b67cd (diff) | |
| download | mariadb-git-519bb2e41cee2d76826ae29d43c13941ebcf82c4.tar.gz | |
disallow {:p}
by printing a String as an std::string_view, not as a char*
| -rw-r--r-- | mysql-test/main/func_sformat.result | 8 | ||||
| -rw-r--r-- | mysql-test/main/func_sformat.test | 5 | ||||
| -rw-r--r-- | sql/item_strfunc.cc | 17 |
3 files changed, 29 insertions, 1 deletions
diff --git a/mysql-test/main/func_sformat.result b/mysql-test/main/func_sformat.result index 913a021f1b5..a49cc277aca 100644 --- a/mysql-test/main/func_sformat.result +++ b/mysql-test/main/func_sformat.result @@ -409,3 +409,11 @@ select a, sformat('{:.15f}', a) from t2; a sformat('{:.15f}', a) 3.141592653589793 3.141592653589793 drop table t2; +# +# Unsupported/disabled features +# +select sformat('{:p}', '50'); +sformat('{:p}', '50') +NULL +Warnings: +Warning 4183 SFORMAT error: invalid type specifier diff --git a/mysql-test/main/func_sformat.test b/mysql-test/main/func_sformat.test index f2239b1b06d..bbbf0d0d576 100644 --- a/mysql-test/main/func_sformat.test +++ b/mysql-test/main/func_sformat.test @@ -183,3 +183,8 @@ create table t2 (a double); insert into t2 values (3.14159265358979323846); select a, sformat('{:.15f}', a) from t2; drop table t2; + +echo #; +echo # Unsupported/disabled features; +echo #; +select sformat('{:p}', '50'); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 102216a5aa7..628e731438b 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1320,6 +1320,21 @@ bool Item_func_sformat::fix_length_and_dec() } /* + allow fmt to take String arguments directly. + Inherit from string_view, so all string formatting works. + but {:p} doesn't, because it's not char*, not a pointer. +*/ +namespace fmt { + template <> struct formatter<String>: formatter<string_view> { + template <typename FormatContext> + auto format(String c, FormatContext& ctx) -> decltype(ctx.out()) { + string_view name = { c.ptr(), c.length() }; + return formatter<string_view>::format(name, ctx); + }; + }; +}; + +/* SFORMAT(format_string, ...) This function receives a formatting specification string and N parameters (N >= 0), and it returns string formatted using the rules the user passed @@ -1369,7 +1384,7 @@ String *Item_func_sformat::val_str(String *res) if (parg->length() == 1) vargs[carg-1]= fmt::detail::make_arg<ctx>(parg->ptr()[0]); else - vargs[carg-1]= fmt::detail::make_arg<ctx>(parg->c_ptr_safe()); + vargs[carg-1]= fmt::detail::make_arg<ctx>(*parg); break; case TIME_RESULT: // TODO case ROW_RESULT: // TODO |
