Skip to content

Commit 521b3af

Browse files
committed
Merge pull request #506
2 parents 8b7d4c1 + e9271bf commit 521b3af

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

php_phongo.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,15 @@ void php_phongo_new_decimal128(zval *object, const bson_decimal128_t *decimal TS
16661666
intern->initialized = true;
16671667
} /* }}} */
16681668

1669+
/* qsort() compare callback for alphabetizing regex flags upon initialization */
1670+
static int php_phongo_regex_compare_flags(const void *f1, const void *f2) {
1671+
if (* (const char *) f1 == * (const char *) f2) {
1672+
return 0;
1673+
}
1674+
1675+
return (* (const char *) f1 > * (const char *) f2) ? 1 : -1;
1676+
}
1677+
16691678
void php_phongo_new_regex_from_regex_and_options(zval *object, const char *pattern, const char *flags TSRMLS_DC) /* {{{ */
16701679
{
16711680
php_phongo_regex_t *intern;
@@ -1677,6 +1686,10 @@ void php_phongo_new_regex_from_regex_and_options(zval *object, const char *patte
16771686
intern->pattern = estrndup(pattern, intern->pattern_len);
16781687
intern->flags_len = strlen(flags);
16791688
intern->flags = estrndup(flags, intern->flags_len);
1689+
1690+
/* Ensure flags are alphabetized upon initialization. This may be removed
1691+
* once CDRIVER-1883 is implemented. */
1692+
qsort((void *) intern->flags, intern->flags_len, 1, php_phongo_regex_compare_flags);
16801693
} /* }}} */
16811694

16821695
/* {{{ Memory allocation wrappers */

0 commit comments

Comments
 (0)