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

How to Determine the Exact Cause of "tidyParseBuffer" Error #1123

Open
magicalowl opened this issue Aug 13, 2024 · 0 comments
Open

How to Determine the Exact Cause of "tidyParseBuffer" Error #1123

magicalowl opened this issue Aug 13, 2024 · 0 comments

Comments

@magicalowl
Copy link

magicalowl commented Aug 13, 2024

Hello, when I use tidyParseBuffer, an error sometimes occurs (the return value is 2).
I tried using a buffer to obtain the error message and got the following information [Note 1]:

Tidy found 5 warnings and 1 error! Not all warnings/errors were shown.

This document has errors that must be fixed before using HTML Tidy to generate a tidied up version.

This is confusing. How could I determine the exact cause of the error?

Here is my environment information:

Tidy version: 5.6.0
OS: Oracle Linux 8.8

Here is the content that caused the tidyParseBuffer error [Note 2]:
<div>\n<div itemprop=\"copy-paste-block\"><span style=\"font-size:14px\">\"</span><a href=\"https://mymbtest-my.sharepoint.com/:v:/g/personal/tzute_mymbtest_onmicrosoft_com/EVQTCMelNmNIgZPSY5G3kgABnDjFzGoK9CyojZ-OQ86ciA\" rel=\"noreferrer noopener\" target=\"_blank\" title=\"https://mymbtest-my.sharepoint.com/:v:/g/personal/tzute_mymbtest_onmicrosoft_com/evqtcmelnmnigzpsy5g3kgabndjfzgok9cyojz-oq86cia\" style=\"font-size:14px\">https://mymbtest-my.sharepoint.com/:v:/g/personal/tzute_mymbtest_onmicrosoft_com/EVQTCMelNmNIgZPSY5G3kgABnDjFzGoK9CyojZ-OQ86ciA</a><span style=\"font-size:14px\">\"</span></div>\n</div><attachment id=\"C7081354-36A5-4863-8193-D26391B79200\"></attachment>

Here is a sample code:

bool HasTag(const char *content, size_t content_size, const char *tag)
{
    bool ret_code = false;
    TidyDoc tdoc = NULL;
    TidyBuffer input_buffer;
    TidyBuffer error_buffer = {0};
    int res = 0;

    tidyBufInit(&input_buffer);

    tdoc = tidyCreate();
    tidyOptSetBool(tdoc, TidyShowWarnings, no);
    tidyOptSetBool(tdoc, TidyShowInfo, no);
    tidyOptSetInt(tdoc, TidyShowErrors, 0);
    tidySetErrorBuffer(tdoc, &error_buffer);

    tidyBufAttach(&input_buffer, (void*)content, content_size);    //[Note 2]

    res = tidyParseBuffer(tdoc, &input_buffer);
    if (res >= 0) {
        res = tidyCleanAndRepair(tdoc);
        if (res >= 0) {
            res = tidyRunDiagnostics(tdoc);
            if (res >= 0) {
                dumpNode(tdoc, tidyGetRoot(tdoc), 0);
                printf("%s\n", error_buffer.bp);    //[Note 1]
            }
        }
    }
    
    // ...

    tidyBufFree(&input_buffer);
    tidyBufFree(&error_buffer);

    return ret_code;
}

If you could provide any suggestions, I would greatly appreciate it.

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

1 participant