[pcre-dev] [Bug 565] New: Not an empty string with pcre_cop…

Góra strony
Delete this message
Autor: Kris Gybels
Data:  
Dla: pcre-dev
Temat: [pcre-dev] [Bug 565] New: Not an empty string with pcre_copy_named_substring for unmatched duplicate names
------- You are receiving this mail because: -------
You are on the CC list for the bug.

http://bugs.exim.org/show_bug.cgi?id=565
           Summary: Not an empty string with pcre_copy_named_substring for
                    unmatched duplicate names
           Product: PCRE
           Version: 7.2
          Platform: Macintosh
        OS/Version: All
            Status: NEW
          Severity: bug
          Priority: medium
         Component: Code
        AssignedTo: ph10@???
        ReportedBy: kris.gybels@???
                CC: pcre-dev@???



The PCRE API documentation describes the following in the section "DUPLICATE
SUBPATTERN NAMES":

When duplicates are present, pcre_copy_named_substring() and
pcre_get_named_substring() return the first substring corresponding to the
given name that is set. If none are set, an empty string is returned.

However, I found that the code below gives results that seem to contradict the
above. The code matches a string "qux" against the regular expression
"(?<field>foo)|(?<field>bar)". It then gets the value of the named pattern
"field" in a variable field_value, which was previously assigned to hold the
string "ERR". Based on the above description, since "field" has not been
matched, I would expect pcre_copy_named_substring to set field_value[0] to 0,
so that it contains an empty string. But this does not seem to be the case.

Maybe I just misinterpreted the documentation? If my interpretation of the
documentation is correct, I would personally rather see the code fixed to
matched the documentation than the other way around. I think setting the return
string to be empty in case of an unmatched duplicate name makes sense, at least
for the way I have been using the PCRE library.

The full code:

void bug_report()
{
        int           error_code;
        int           error_offset;
        char *        error_description;
        pcre *        compiled_regexp;
        int           captured_subpatterns[3*3];
        int           number_of_substrings;
        char          field_value[4] = "ERR";
        char *        match_string = "qux";
        int           return_value;


        compiled_regexp = pcre_compile2("(?<field>foo)|(?<field>bar)",
PCRE_DUPNAMES, &error_code, (const char **) &error_description, &error_offset,
NULL);
        number_of_substrings = pcre_exec(compiled_regexp, NULL, match_string,
3, 0, 0, captured_subpatterns, 3*3);


        return_value = pcre_copy_named_substring(compiled_regexp, match_string,
captured_subpatterns, number_of_substrings, "field", field_value, 4);


        printf("Return value is %i, value of field is: [%s]", return_value,
field_value);
}



--
Configure bugmail: http://bugs.exim.org/userprefs.cgi?tab=email