Skip to content

Commit f89121b

Browse files
committed
Unicode Specials block bug correction
1 parent e163079 commit f89121b

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

src/ly_common.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,13 @@ ly_pat_compile_posix(const char *pattern, void **pat_comp, struct ly_err_item **
724724
static LY_ERR
725725
ly_pat_compile_xmlschema_chblocks_xmlschema2perl(const char *pattern, char **regex, struct ly_err_item **err)
726726
{
727-
struct ublock_s {
728-
char *ublock;
729-
char *urange;
730-
size_t size;
731-
};
727+
struct ublock_s {
728+
char *ublock;
729+
char *urange;
730+
size_t size;
731+
};
732732
struct ublock_s ublock2urange[] = {
733-
{"BasicLatin", "[\\x{0000}-\\x{007F}]",19},
733+
{"BasicLatin", "[\\x{0000}-\\x{007F}]", 19},
734734
{"Latin-1Supplement", "[\\x{0080}-\\x{00FF}]", 19},
735735
{"LatinExtended-A", "[\\x{0100}-\\x{017F}]", 19},
736736
{"LatinExtended-B", "[\\x{0180}-\\x{024F}]", 19},
@@ -833,7 +833,6 @@ struct ublock_s {
833833
}
834834
end = (ptr - perl_regex) + 1;
835835

836-
837836
/* find our range */
838837
for (idx = 0; ublock2urange[idx].ublock; ++idx) {
839838
if (!strncmp(perl_regex + start + ly_strlen_const("\\p{Is"),
@@ -848,16 +847,16 @@ struct ublock_s {
848847
ublock = idx;
849848

850849
/* need more space */
851-
size_t urange_len = ublock2urange[ublock].size;
852-
if(end - start < urange_len ) {
850+
size_t urange_len = ublock2urange[ublock].size;
851+
852+
if (end - start < urange_len) {
853853
perl_regex = ly_realloc(perl_regex, strlen(perl_regex) + (urange_len - (end - start)) + 1);
854854
*regex = perl_regex;
855855
if (!perl_regex) {
856856
return ly_err_new(err, LY_EMEM, 0, NULL, NULL, LY_EMEM_MSG);
857857
}
858858
}
859859

860-
861860
/* make the space in the string and replace the block (but we cannot include brackets if it was already enclosed in them) */
862861
for (idx2 = 0, idx = 0; idx2 < start; ++idx2) {
863862
if ((perl_regex[idx2] == '[') && (!idx2 || (perl_regex[idx2 - 1] != '\\'))) {
@@ -1119,6 +1118,7 @@ ly_pat_match_xmlschema(const void *pat_comp, const char *pattern, const char *st
11191118
int r, match_opts = 0;
11201119
pcre2_code *pcode = (void *)pat_comp;
11211120
pcre2_match_data *match_data = NULL;
1121+
11221122
if (!pat_comp) {
11231123
/* compile pattern first */
11241124
rc = ly_pat_compile_xmlschema(pattern, (void **)&pcode, err);

tests/utests/types/string.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,20 @@ test_data_xml(void **state)
865865
"is not valid (\"UnknownUnicodeBlock}]+\": unknown block name).", "/T_UB_8:port", 0);
866866

867867
schema = MODULE_CREATE_YANG("T_UB_9", "leaf port {type string { pattern "
868-
"'[\\p{IsSpecials}]+';}}");
868+
"'[\\p{IsSpecials}]+';}}");
869869
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
870870
TEST_SUCCESS_XML("T_UB_9", "&#xFFFA;&#xFFFD;", STRING, "\xef\xbf\xba\xef\xbf\xbd");
871+
872+
schema = MODULE_CREATE_YANG("T_UB_10", "leaf port {type string { pattern "
873+
"'[\\p{IsSpecials}]+';}}");
874+
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
875+
TEST_ERROR_XML("T_UB_10", "&#xFFDF;&#xFFFD;");
876+
CHECK_LOG_CTX("Unsatisfied pattern - \"\xef\xbf\x9f\xef\xbf\xbd\" does not match \"[\\p{IsSpecials}]+\".", "/T_UB_10:port", 1);
877+
878+
schema = MODULE_CREATE_YANG("T_UB_11", "leaf port {type string { pattern "
879+
"'[\\p{IsSpecials}]+';}}");
880+
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
881+
TEST_SUCCESS_XML("T_UB_11", "&#xFEFF;&#xFFFD;", STRING, "\xef\xbb\xbf\xef\xbf\xbd");
871882
}
872883

873884
static void

0 commit comments

Comments
 (0)