-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for parsing XML with WebCore and libxml2 in the same process
https://bugs.webkit.org/show_bug.cgi?id=273553 <rdar://127295719> Reviewed by Alex Christensen. The xmlCtxtReadFile() function calls xmlLoadExternalEntity() as part of its implementation (not sure why), which would then trigger the external entity loader path. Prior to the fix in 278168@main, WebCore replaced the global external entity loader function and didn't change it back when it was done, which caused libxml2 loads to fail. The fix restores the default external entity loader function when WebCore is done parsing XML, so making WebCore parse XMl content, then calling xmlCtxtReadFile() is sufficient to test the fix. API Test: TestWebKitAPI.XMLParsing.WebCoreDoesNotBreakLibxml2 * Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig: (OTHER_LDFLAGS): Link libxml2 to TestWebKitAPI. * Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: - Add XMLParsing.mm and test.xml to the project. * Tools/TestWebKitAPI/Tests/WebCore/XMLParsing.mm: Add. (TestWebKitAPI::TEST(XMLParsing, WebCoreDoesNotBreakLibxml2)): * Tools/TestWebKitAPI/Tests/WebKit/test.xml: Add. Canonical link: https://commits.webkit.org/278253@main
- Loading branch information
Showing
4 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include "PlatformUtilities.h" | ||
#include "WebCoreTestSupport.h" | ||
#include <WebCore/ParserContentPolicy.h> | ||
#include <libxml/parser.h> | ||
|
||
namespace TestWebKitAPI { | ||
|
||
TEST(XMLParsing, WebCoreDoesNotBreakLibxml2) | ||
{ | ||
// Parse XHTML in WebKit. | ||
String chunk = "<x/>"_s; | ||
auto result = WebCoreTestSupport::testDocumentFragmentParseXML(chunk, WebCore::DefaultParserContentPolicy); | ||
EXPECT_TRUE(result); | ||
|
||
NSString *resourceURL = [[[NSBundle mainBundle] URLForResource:@"test" withExtension:@"xml" subdirectory:@"TestWebKitAPI.resources"] path]; | ||
|
||
// Parse an XML document in libxml2. | ||
xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); | ||
EXPECT_TRUE(!!ctxt); | ||
xmlDocPtr doc = xmlCtxtReadFile(ctxt, resourceURL.UTF8String, nullptr, XML_PARSE_NONET); | ||
EXPECT_TRUE(!!doc); | ||
xmlFreeDoc(doc); | ||
xmlFreeParserCtxt(ctxt); | ||
} | ||
|
||
} // namespace TestWebKitAPI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<x></x> |