[ion] Storage: make Storage::nameCompliant less restrictive (accepts

.*\.[a-z]+). But Script::nameCompliant is stricted: [a-z_0-9.]*
This commit is contained in:
Émilie Feral
2018-09-13 11:07:16 +02:00
parent 51341f4abe
commit 08077cb141
6 changed files with 24 additions and 11 deletions

View File

@@ -316,7 +316,7 @@ bool MenuController::textFieldDidFinishEditing(TextField * textField, const char
} else {
newName = text;
}
Script::ErrorStatus error = m_scriptStore->scriptAtIndex(m_selectableTableView.selectedRow()).setName(newName);
Script::ErrorStatus error = Script::nameCompliant(newName) ? m_scriptStore->scriptAtIndex(m_selectableTableView.selectedRow()).setName(newName) : Script::ErrorStatus::NonCompliantName;
if (error == Script::ErrorStatus::None) {
updateAddScriptRowDisplay();
textField->setText(newName);

View File

@@ -25,4 +25,17 @@ const char * Script::readContent() const {
return (const char *)d.buffer+k_importationStatusSize;
}
bool Script::nameCompliant(const char * name) {
/* The name format is [a-z0-9_.]* */
const char * currentChar = name;
while (*currentChar != 0) {
if ((*currentChar >= 'a' && *currentChar <= 'z') || *currentChar == '_' || (*currentChar >= '0' && *currentChar <= '9') || *currentChar == '.') {
currentChar++;
continue;
}
return false;
}
return name != currentChar;
}
}

View File

@@ -17,6 +17,8 @@ public:
const char * readContent() const;
static bool nameCompliant(const char * name);
constexpr static size_t k_importationStatusSize = 1;
};

View File

@@ -121,6 +121,7 @@ const char * ScriptStore::contentOfScript(const char * name) {
Script::ErrorStatus ScriptStore::addScriptFromTemplate(const ScriptTemplate * scriptTemplate) {
size_t valueSize = strlen(scriptTemplate->content())+1+1;// scriptcontent size + 1 char for the importation status
assert(Script::nameCompliant(scriptTemplate->name()));
Script::ErrorStatus err = Ion::Storage::sharedStorage()->createRecord(scriptTemplate->name(), scriptTemplate->value(), valueSize);
assert(err != Script::ErrorStatus::NonCompliantName);
return err;