Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not handle attributes with spaces in the content #33

Open
nashidau opened this issue Jan 16, 2023 · 2 comments
Open

Does not handle attributes with spaces in the content #33

nashidau opened this issue Jan 16, 2023 · 2 comments

Comments

@nashidau
Copy link

<a foo="Has Spaces">

Gives an attribute foo with value "Has"

@ooxi
Copy link
Owner

ooxi commented Jan 19, 2023

This is unexpected thanks for the report!

Update: I can reproduce this issue, most likely caused by using strtok_r to look for " ".

I'm not sure if I will be able to fix this soon. Would you be able to encode the space using &#032; followed by a decoding step?

ooxi added a commit that referenced this issue Jan 19, 2023
@ooxi ooxi mentioned this issue May 26, 2023
@ArtemkaKun
Copy link

ArtemkaKun commented Jan 9, 2024

I rewrote code like that and seems it works for my cases

static char* xml_strtok_r(char *str, const char *delim, char **nextp) {
    char *ret;
    int in_quote = 0;
    char quote_char = 0;

    if (str == NULL) {
        str = *nextp;
    }

    // Skip leading delimiters
    str += strspn(str, delim);

    if (*str == '\0') {
        return NULL;
    }

    ret = str;

    while (*str) {
        if (!in_quote && strchr(delim, *str)) { // Found a delimiter outside quotes
            *str++ = '\0';
            break;
        } else if ((*str == '"' || *str == '\'') && (in_quote == 0 || quote_char == *str)) {
            in_quote = !in_quote; // Toggle in_quote
            quote_char = in_quote ? *str : 0; // Set or reset quote_char
        }
        ++str;
    }

    *nextp = str;
    return ret;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants