mirror of https://gitee.com/bigwinds/arangodb
issue #277
This commit is contained in:
parent
2849b4555f
commit
3009bdfcfd
|
@ -4,6 +4,8 @@ v1.1.beta3 (XXXX-XX-XX)
|
||||||
the fix of this issue also implies validation of collection names / ids passed to
|
the fix of this issue also implies validation of collection names / ids passed to
|
||||||
the REST edge create method. edges with invalid collection ids or names in the
|
the REST edge create method. edges with invalid collection ids or names in the
|
||||||
"from" or "to" values will be rejected and not saved
|
"from" or "to" values will be rejected and not saved
|
||||||
|
Also allow using collection names in document ids when creating edges from
|
||||||
|
Javascript using the edges.<collection>.save(from, to, data) method
|
||||||
|
|
||||||
|
|
||||||
v1.1.beta2 (2012-11-13)
|
v1.1.beta2 (2012-11-13)
|
||||||
|
|
|
@ -272,7 +272,10 @@ static inline TRI_vocbase_t* GetContextVocBase () {
|
||||||
/// @brief checks if argument is a document identifier
|
/// @brief checks if argument is a document identifier
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static bool IsDocumentHandle (v8::Handle<v8::Value> arg, TRI_voc_cid_t& cid, TRI_voc_key_t& key) {
|
static bool IsDocumentHandle (TRI_vocbase_t* const vocbase,
|
||||||
|
v8::Handle<v8::Value> arg,
|
||||||
|
TRI_voc_cid_t& cid,
|
||||||
|
TRI_voc_key_t& key) {
|
||||||
TRI_v8_global_t* v8g;
|
TRI_v8_global_t* v8g;
|
||||||
|
|
||||||
v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData();
|
v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData();
|
||||||
|
@ -297,6 +300,19 @@ static bool IsDocumentHandle (v8::Handle<v8::Value> arg, TRI_voc_cid_t& cid, TRI
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "cname/key"
|
||||||
|
if (regexec(&v8g->DocumentId2Regex, s, sizeof(matches) / sizeof(matches[0]), matches, 0) == 0) {
|
||||||
|
const string name = string(s + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);
|
||||||
|
TRI_vocbase_col_t* col = TRI_LookupCollectionByNameVocBase(vocbase, name.c_str());
|
||||||
|
if (col == 0) {
|
||||||
|
// colleciton not found
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
cid = col->_cid;
|
||||||
|
key = TRI_DuplicateString2Z(TRI_CORE_MEM_ZONE, s + matches[2].rm_so, matches[2].rm_eo - matches[2].rm_so);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// "key"
|
// "key"
|
||||||
if (regexec(&v8g->DocumentKeyRegex, s, 0, NULL, 0) == 0) {
|
if (regexec(&v8g->DocumentKeyRegex, s, 0, NULL, 0) == 0) {
|
||||||
key = TRI_DuplicateString2Z(TRI_CORE_MEM_ZONE, *str, str.length());
|
key = TRI_DuplicateString2Z(TRI_CORE_MEM_ZONE, *str, str.length());
|
||||||
|
@ -5979,7 +5995,7 @@ v8::Handle<v8::Value> TRI_ParseDocumentOrDocumentHandle (TRI_vocbase_t* vocbase,
|
||||||
|
|
||||||
// extract the document identifier and revision from a string
|
// extract the document identifier and revision from a string
|
||||||
if (val->IsString() || val->IsStringObject()) {
|
if (val->IsString() || val->IsStringObject()) {
|
||||||
if (! IsDocumentHandle(val, cid, key)) {
|
if (! IsDocumentHandle(vocbase, val, cid, key)) {
|
||||||
return scope.Close(TRI_CreateErrorObject(TRI_ERROR_ARANGO_DOCUMENT_HANDLE_BAD,
|
return scope.Close(TRI_CreateErrorObject(TRI_ERROR_ARANGO_DOCUMENT_HANDLE_BAD,
|
||||||
"<document-handle> must be a document-handle"));
|
"<document-handle> must be a document-handle"));
|
||||||
}
|
}
|
||||||
|
@ -5990,7 +6006,7 @@ v8::Handle<v8::Value> TRI_ParseDocumentOrDocumentHandle (TRI_vocbase_t* vocbase,
|
||||||
v8::Handle<v8::Object> obj = val->ToObject();
|
v8::Handle<v8::Object> obj = val->ToObject();
|
||||||
v8::Handle<v8::Value> didVal = obj->Get(v8g->DidKey);
|
v8::Handle<v8::Value> didVal = obj->Get(v8g->DidKey);
|
||||||
|
|
||||||
if (! IsDocumentHandle(didVal, cid, key)) {
|
if (! IsDocumentHandle(vocbase, didVal, cid, key)) {
|
||||||
return scope.Close(TRI_CreateErrorObject(TRI_ERROR_ARANGO_DOCUMENT_HANDLE_BAD,
|
return scope.Close(TRI_CreateErrorObject(TRI_ERROR_ARANGO_DOCUMENT_HANDLE_BAD,
|
||||||
"expecting a document-handle in _id"));
|
"expecting a document-handle in _id"));
|
||||||
}
|
}
|
||||||
|
@ -6277,22 +6293,34 @@ TRI_v8_global_t* TRI_InitV8VocBridge (v8::Handle<v8::Context> context,
|
||||||
isolate->SetData(v8g);
|
isolate->SetData(v8g);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the regular expressions
|
const string colExpr = "[a-zA-Z][0-9a-zA-Z_-]*";
|
||||||
string expr = "([0-9][0-9]*)" + string(TRI_DOCUMENT_HANDLE_SEPARATOR_STR) + "([0-9a-zA-Z][0-9a-zA-Z]*)";
|
const string keyExpr = "[0-9a-zA-Z][0-9a-zA-Z]*";
|
||||||
|
const string idExpr = "[0-9][0-9]*";
|
||||||
|
string expr;
|
||||||
|
|
||||||
|
// create the regular expressions
|
||||||
|
expr = "^(" + idExpr + ")" + string(TRI_DOCUMENT_HANDLE_SEPARATOR_STR) + "(" + keyExpr + ")$";
|
||||||
if (regcomp(&v8g->DocumentIdRegex, expr.c_str(), REG_ICASE | REG_EXTENDED) != 0) {
|
if (regcomp(&v8g->DocumentIdRegex, expr.c_str(), REG_ICASE | REG_EXTENDED) != 0) {
|
||||||
LOG_FATAL("cannot compile regular expression");
|
LOG_FATAL("cannot compile regular expression");
|
||||||
TRI_FlushLogging();
|
TRI_FlushLogging();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expr = "^(" + colExpr + ")" + string(TRI_DOCUMENT_HANDLE_SEPARATOR_STR) + "(" + keyExpr + ")$";
|
||||||
|
if (regcomp(&v8g->DocumentId2Regex, expr.c_str(), REG_ICASE | REG_EXTENDED) != 0) {
|
||||||
|
LOG_FATAL("cannot compile regular expression");
|
||||||
|
TRI_FlushLogging();
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
expr = "^(" + idExpr + ")" + string(TRI_DOCUMENT_HANDLE_SEPARATOR_STR) + "(" + idExpr + ")$";
|
||||||
if (regcomp(&v8g->IndexIdRegex, expr.c_str(), REG_ICASE | REG_EXTENDED) != 0) {
|
if (regcomp(&v8g->IndexIdRegex, expr.c_str(), REG_ICASE | REG_EXTENDED) != 0) {
|
||||||
LOG_FATAL("cannot compile regular expression");
|
LOG_FATAL("cannot compile regular expression");
|
||||||
TRI_FlushLogging();
|
TRI_FlushLogging();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
expr = "^[0-9a-zA-Z][_0-9a-zA-Z]*$";
|
expr = "^" + keyExpr + "$";
|
||||||
if (regcomp(&v8g->DocumentKeyRegex, expr.c_str(), REG_ICASE | REG_EXTENDED) != 0) {
|
if (regcomp(&v8g->DocumentKeyRegex, expr.c_str(), REG_ICASE | REG_EXTENDED) != 0) {
|
||||||
LOG_FATAL("cannot compile regular expression");
|
LOG_FATAL("cannot compile regular expression");
|
||||||
TRI_FlushLogging();
|
TRI_FlushLogging();
|
||||||
|
|
|
@ -106,6 +106,7 @@ typedef struct TRI_v8_global_s {
|
||||||
UserKey(),
|
UserKey(),
|
||||||
WaitForSyncKey(),
|
WaitForSyncKey(),
|
||||||
DocumentIdRegex(),
|
DocumentIdRegex(),
|
||||||
|
DocumentId2Regex(),
|
||||||
DocumentKeyRegex(),
|
DocumentKeyRegex(),
|
||||||
IndexIdRegex(),
|
IndexIdRegex(),
|
||||||
_currentTransaction() {
|
_currentTransaction() {
|
||||||
|
@ -113,6 +114,7 @@ typedef struct TRI_v8_global_s {
|
||||||
|
|
||||||
~TRI_v8_global_s () {
|
~TRI_v8_global_s () {
|
||||||
regfree(&DocumentIdRegex);
|
regfree(&DocumentIdRegex);
|
||||||
|
regfree(&DocumentId2Regex);
|
||||||
regfree(&DocumentKeyRegex);
|
regfree(&DocumentKeyRegex);
|
||||||
regfree(&IndexIdRegex);
|
regfree(&IndexIdRegex);
|
||||||
}
|
}
|
||||||
|
@ -398,11 +400,17 @@ typedef struct TRI_v8_global_s {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief document identifier as collection-id:document-id
|
/// @brief document identifier as collection-id/key
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
regex_t DocumentIdRegex;
|
regex_t DocumentIdRegex;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief document identifier as collection-name/key
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
regex_t DocumentId2Regex;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief document identifier
|
/// @brief document identifier
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue