@@ -129,6 +129,11 @@ class Document implements \JsonSerializable
129
129
* keepNull option index
130
130
*/
131
131
const OPTION_KEEPNULL = 'keepNull ' ;
132
+
133
+ /**
134
+ * regular expression used for key validation
135
+ */
136
+ const KEY_REGEX_PART = '[a-zA-Z0-9_:.@ \\-()+,=;$!* \'%]{1,254} ' ;
132
137
133
138
/**
134
139
* Constructs an empty document
@@ -299,25 +304,21 @@ public function set($key, $value)
299
304
if ($ key [0 ] === '_ ' ) {
300
305
if ($ key === self ::ENTRY_ID ) {
301
306
$ this ->setInternalId ($ value );
302
-
303
307
return ;
304
308
}
305
309
306
310
if ($ key === self ::ENTRY_KEY ) {
307
311
$ this ->setInternalKey ($ value );
308
-
309
312
return ;
310
313
}
311
314
312
315
if ($ key === self ::ENTRY_REV ) {
313
316
$ this ->setRevision ($ value );
314
-
315
317
return ;
316
318
}
317
319
318
320
if ($ key === self ::ENTRY_ISNEW ) {
319
321
$ this ->setIsNew ($ value );
320
-
321
322
return ;
322
323
}
323
324
}
@@ -638,7 +639,7 @@ public function setInternalId($id)
638
639
}
639
640
640
641
641
- if (!preg_match ('/^[a-zA-Z0-9_-]{1,64}\/[a-zA-Z0-9_:.@\-()+,=;$!* \' %]{1,254} $/ ' , $ id )) {
642
+ if (!preg_match ('/^[a-zA-Z0-9_-]{1,64}\/ ' . self :: KEY_REGEX_PART . ' $/ ' , $ id )) {
642
643
throw new ClientException ('Invalid format for document id ' );
643
644
}
644
645
@@ -662,7 +663,7 @@ public function setInternalKey($key)
662
663
throw new ClientException ('Should not update the key of an existing document ' );
663
664
}
664
665
665
- if (!preg_match ('/^[a-zA-Z0-9_:.@\-()+,=;$!* \' %]{1,254} $/ ' , $ key )) {
666
+ if (!preg_match ('/^ ' . self :: KEY_REGEX_PART . ' $/ ' , $ key )) {
666
667
throw new ClientException ('Invalid format for document key ' );
667
668
}
668
669
0 commit comments