mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion] Storage: make Storage::nameCompliant less restrictive (accepts
.*\.[a-z]+). But Script::nameCompliant is stricted: [a-z_0-9.]*
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,8 @@ public:
|
||||
|
||||
const char * readContent() const;
|
||||
|
||||
static bool nameCompliant(const char * name);
|
||||
|
||||
constexpr static size_t k_importationStatusSize = 1;
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -86,7 +86,7 @@ private:
|
||||
size_t overrideValueAtPosition(char * position, const void * data, record_size_t size);
|
||||
|
||||
bool isNameTaken(const char * name, Record * recordToExclude = nullptr);
|
||||
bool nameCompliant(const char * name) const;
|
||||
static bool nameCompliant(const char * name);
|
||||
char * endBuffer();
|
||||
size_t sizeOfRecord(const char * name, size_t size) const;
|
||||
bool slideBuffer(char * position, int delta);
|
||||
|
||||
@@ -278,25 +278,22 @@ bool Storage::isNameTaken(const char * name, Record * recordToExclude) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Storage::nameCompliant(const char * name) const {
|
||||
/* The name format is [a-z0-9_]*(\.)?[a-z0-9_]+ */
|
||||
bool Storage::nameCompliant(const char * name) {
|
||||
/* The name format is .*(\.)?[a-z]+ */
|
||||
bool dot = false;
|
||||
const char * currentChar = name;
|
||||
while (*currentChar != 0) {
|
||||
if (*currentChar == '.') {
|
||||
if (dot) {
|
||||
return false;
|
||||
} else {
|
||||
dot = true;
|
||||
}
|
||||
dot = true;
|
||||
currentChar++;
|
||||
}
|
||||
if ((*currentChar >= 'a' && *currentChar <= 'z') || *currentChar == '_' || (*currentChar >= '0' && *currentChar <= '9') || *currentChar == '.') {
|
||||
if (!dot || (*currentChar >= 'a' && *currentChar <= 'z')) {
|
||||
currentChar++;
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return name != currentChar;
|
||||
return name != currentChar && dot;
|
||||
}
|
||||
|
||||
char * Storage::endBuffer() {
|
||||
|
||||
Reference in New Issue
Block a user