| 114 | /************************************************************************/ |
| 115 | |
| 116 | static bool CPLHasLibXMLBug() |
| 117 | { |
| 118 | static bool bHasLibXMLBug = false; |
| 119 | static bool bLibXMLBugChecked = false; |
| 120 | if (bLibXMLBugChecked) |
| 121 | return bHasLibXMLBug; |
| 122 | |
| 123 | constexpr char szLibXMLBugTester[] = |
| 124 | "<schema targetNamespace=\"http://foo\" " |
| 125 | "xmlns:foo=\"http://foo\" xmlns=\"http://www.w3.org/2001/XMLSchema\">" |
| 126 | "<simpleType name=\"t1\">" |
| 127 | "<list itemType=\"double\"/>" |
| 128 | "</simpleType>" |
| 129 | "<complexType name=\"t2\">" |
| 130 | "<simpleContent>" |
| 131 | "<extension base=\"foo:t1\"/>" |
| 132 | "</simpleContent>" |
| 133 | "</complexType>" |
| 134 | "<complexType name=\"t3\">" |
| 135 | "<simpleContent>" |
| 136 | "<restriction base=\"foo:t2\">" |
| 137 | "<length value=\"2\"/>" |
| 138 | "</restriction>" |
| 139 | "</simpleContent>" |
| 140 | "</complexType>" |
| 141 | "</schema>"; |
| 142 | |
| 143 | xmlSchemaParserCtxtPtr pSchemaParserCtxt = |
| 144 | xmlSchemaNewMemParserCtxt(szLibXMLBugTester, strlen(szLibXMLBugTester)); |
| 145 | |
| 146 | xmlSchemaSetParserErrors(pSchemaParserCtxt, CPLHasLibXMLBugWarningCallback, |
| 147 | CPLHasLibXMLBugWarningCallback, nullptr); |
| 148 | |
| 149 | xmlSchemaPtr pSchema = xmlSchemaParse(pSchemaParserCtxt); |
| 150 | xmlSchemaFreeParserCtxt(pSchemaParserCtxt); |
| 151 | |
| 152 | bHasLibXMLBug = pSchema == nullptr; |
| 153 | bLibXMLBugChecked = true; |
| 154 | |
| 155 | if (pSchema) |
| 156 | xmlSchemaFree(pSchema); |
| 157 | |
| 158 | if (bHasLibXMLBug) |
| 159 | { |
| 160 | CPLDebug("CPL", |
| 161 | "LibXML bug found " |
| 162 | "(cf https://bugzilla.gnome.org/show_bug.cgi?id=630130). " |
| 163 | "Will try to workaround for GML schemas."); |
| 164 | } |
| 165 | |
| 166 | return bHasLibXMLBug; |
| 167 | } |
| 168 | |
| 169 | #endif |
| 170 |
no test coverage detected