Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50252a37 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE Truncate new line characters when adding string to config" into oc-dev

parents cf09fecb 5278a8b9
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include "osi/include/allocator.h"
#include "osi/include/list.h"
#include "osi/include/log.h"
#include "log/log.h"

typedef struct {
  char* key;
@@ -217,17 +218,27 @@ void config_set_string(config_t* config, const char* section, const char* key,
    list_append(config->sections, sec);
  }

  std::string value_string = value;
  std::string value_no_newline;
  size_t newline_position = value_string.find("\n");
  if (newline_position != std::string::npos) {
    android_errorWriteLog(0x534e4554, "70808273");
    value_no_newline = value_string.substr(0, newline_position);
  } else {
    value_no_newline = value_string;
  }

  for (const list_node_t* node = list_begin(sec->entries);
       node != list_end(sec->entries); node = list_next(node)) {
    entry_t* entry = static_cast<entry_t*>(list_node(node));
    if (!strcmp(entry->key, key)) {
      osi_free(entry->value);
      entry->value = osi_strdup(value);
      entry->value = osi_strdup(value_no_newline.c_str());
      return;
    }
  }

  entry_t* entry = entry_new(key, value);
  entry_t* entry = entry_new(key, value_no_newline.c_str());
  list_append(sec->entries, entry);
}