diff --git a/esphome/components/api/api_pb2_dump.cpp b/esphome/components/api/api_pb2_dump.cpp index 3317fe9882f..f74aa72741e 100644 --- a/esphome/components/api/api_pb2_dump.cpp +++ b/esphome/components/api/api_pb2_dump.cpp @@ -135,11 +135,13 @@ static void dump_progmem_bytes_field(DumpBuffer &out, const char *field_name, co dump_bytes_field(out, field_name, data_buf, len, indent); } -// Helper for string fields in flash: copies the shown characters out with progmem_memcpy first +// Helper for string fields in flash: copies straight into the dump buffer, which bounds the length static void dump_progmem_string_field(DumpBuffer &out, const char *field_name, const ProgmemStringRef &value, int indent = 2) { - char buf[DUMP_BYTES_MAX]; - dump_field(out, field_name, StringRef(buf, value.write_to(buf, sizeof(buf))), indent); + append_field_prefix(out, field_name, indent); + out.append("'"); + out.set_pos(out.pos() + value.write_to(out.data() + out.pos(), DumpBuffer::CAPACITY - out.pos())); + out.append("'\n"); } #pragma GCC diagnostic pop diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index aaa1663dbba..c0eb46c2777 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -3391,11 +3391,13 @@ static void dump_progmem_bytes_field(DumpBuffer &out, const char *field_name, co dump_bytes_field(out, field_name, data_buf, len, indent); } -// Helper for string fields in flash: copies the shown characters out with progmem_memcpy first +// Helper for string fields in flash: copies straight into the dump buffer, which bounds the length static void dump_progmem_string_field(DumpBuffer &out, const char *field_name, const ProgmemStringRef &value, int indent = 2) { - char buf[DUMP_BYTES_MAX]; - dump_field(out, field_name, StringRef(buf, value.write_to(buf, sizeof(buf))), indent); + append_field_prefix(out, field_name, indent); + out.append("'"); + out.set_pos(out.pos() + value.write_to(out.data() + out.pos(), DumpBuffer::CAPACITY - out.pos())); + out.append("'\\n"); } #pragma GCC diagnostic pop diff --git a/tests/component_tests/api/test_action_metadata.py b/tests/component_tests/api/test_action_metadata.py index 8e7dea4b19a..8bfdb7a7a7d 100644 --- a/tests/component_tests/api/test_action_metadata.py +++ b/tests/component_tests/api/test_action_metadata.py @@ -14,6 +14,7 @@ from esphome.config_validation import Invalid from esphome.core import CORE from esphome.cpp_generator import safe_exp from esphome.helpers import fnv1_hash +from tests.component_tests.helpers import get_define_value CONFIG = "tests/component_tests/api/test_action_metadata.yaml" CONFIG_ESP8266 = "tests/component_tests/api/test_action_metadata_esp8266.yaml" @@ -58,6 +59,7 @@ def test_esp8266_encodes_action_strings_from_flash( main_cpp = generate_main(CONFIG_ESP8266) assert "api_action0_strings[] PROGMEM" in main_cpp + assert get_define_value("API_USER_ACTION_STRINGS_SCRATCH_SIZE") is None def test_shorthand_variables_emit_no_metadata(