From 5d2431a5e1432357412b25ade0c70c65e3c227ce Mon Sep 17 00:00:00 2001 From: David Abram Cargill <cargilld@apache.org> Date: Mon, 12 Jan 2004 16:15:57 +0000 Subject: [PATCH] Avoid throwing malformedurl exceptions in XMLURL to avoid a threading problem on AIX. git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@175663 13f79535-47bb-0310-9956-ffa450edef68 --- src/xercesc/internal/DGXMLScanner.cpp | 31 +-- src/xercesc/internal/IGXMLScanner2.cpp | 63 ++---- src/xercesc/internal/ReaderMgr.cpp | 59 +++--- src/xercesc/internal/SGXMLScanner.cpp | 63 ++---- src/xercesc/internal/XMLScanner.cpp | 180 ++++++++---------- src/xercesc/util/XMLURL.cpp | 34 +++- src/xercesc/util/XMLURL.hpp | 7 +- .../validators/schema/TraverseSchema.cpp | 37 ++-- 8 files changed, 220 insertions(+), 254 deletions(-) diff --git a/src/xercesc/internal/DGXMLScanner.cpp b/src/xercesc/internal/DGXMLScanner.cpp index 8cbc99dad..8e6382b89 100644 --- a/src/xercesc/internal/DGXMLScanner.cpp +++ b/src/xercesc/internal/DGXMLScanner.cpp @@ -2451,27 +2451,10 @@ InputSource* DGXMLScanner::resolveSystemId(const XMLCh* const sysId) ReaderMgr::LastExtEntityInfo lastInfo; fReaderMgr.getLastExtEntityInfo(lastInfo); - try - { - XMLURL urlTmp(lastInfo.systemId, expSysId.getRawBuffer()); - if (urlTmp.isRelative()) - { - ThrowXMLwithMemMgr - ( - MalformedURLException - , XMLExcepts::URL_NoProtocolPresent - , fMemoryManager - ); - } - else { - if (fStandardUriConformant && urlTmp.hasInvalidChar()) - ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); - srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); - } - } - catch(const MalformedURLException& e) + XMLURL urlTmp(fMemoryManager); + if ((!urlTmp.setURL(lastInfo.systemId, expSysId.getRawBuffer(), urlTmp)) || + (urlTmp.isRelative())) { - // Its not a URL, so lets assume its a local file name if non-standard uri is allowed if (!fStandardUriConformant) srcToFill = new (fMemoryManager) LocalFileInputSource ( @@ -2480,8 +2463,14 @@ InputSource* DGXMLScanner::resolveSystemId(const XMLCh* const sysId) , fMemoryManager ); else - throw e; + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); } + else + { + if (fStandardUriConformant && urlTmp.hasInvalidChar()) + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); + srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); + } } return srcToFill; diff --git a/src/xercesc/internal/IGXMLScanner2.cpp b/src/xercesc/internal/IGXMLScanner2.cpp index a24552ac0..36178286a 100644 --- a/src/xercesc/internal/IGXMLScanner2.cpp +++ b/src/xercesc/internal/IGXMLScanner2.cpp @@ -1738,28 +1738,10 @@ void IGXMLScanner::resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* con ReaderMgr::LastExtEntityInfo lastInfo; fReaderMgr.getLastExtEntityInfo(lastInfo); - try + XMLURL urlTmp(fMemoryManager); + if ((!urlTmp.setURL(lastInfo.systemId, expSysId.getRawBuffer(), urlTmp)) || + (urlTmp.isRelative())) { - XMLURL urlTmp(lastInfo.systemId, expSysId.getRawBuffer(), fMemoryManager); - if (urlTmp.isRelative()) - { - ThrowXMLwithMemMgr - ( - MalformedURLException - , XMLExcepts::URL_NoProtocolPresent - , fMemoryManager - ); - } - else { - if (fStandardUriConformant && urlTmp.hasInvalidChar()) - ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); - srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); - } - } - - catch(const MalformedURLException& e) - { - // Its not a URL, so lets assume its a local file name if non-standard uri is allowed if (!fStandardUriConformant) srcToFill = new (fMemoryManager) LocalFileInputSource ( @@ -1768,8 +1750,14 @@ void IGXMLScanner::resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* con , fMemoryManager ); else - throw e; + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); } + else + { + if (fStandardUriConformant && urlTmp.hasInvalidChar()) + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); + srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); + } } // Put a janitor on the input source @@ -1920,27 +1908,10 @@ InputSource* IGXMLScanner::resolveSystemId(const XMLCh* const sysId) ReaderMgr::LastExtEntityInfo lastInfo; fReaderMgr.getLastExtEntityInfo(lastInfo); - try + XMLURL urlTmp(fMemoryManager); + if ((!urlTmp.setURL(lastInfo.systemId, expSysId.getRawBuffer(), urlTmp)) || + (urlTmp.isRelative())) { - XMLURL urlTmp(lastInfo.systemId, expSysId.getRawBuffer()); - if (urlTmp.isRelative()) - { - ThrowXMLwithMemMgr - ( - MalformedURLException - , XMLExcepts::URL_NoProtocolPresent - , fMemoryManager - ); - } - else { - if (fStandardUriConformant && urlTmp.hasInvalidChar()) - ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); - srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); - } - } - catch(const MalformedURLException& e) - { - // Its not a URL, so lets assume its a local file name if non-standard uri is allowed if (!fStandardUriConformant) srcToFill = new (fMemoryManager) LocalFileInputSource ( @@ -1949,8 +1920,14 @@ InputSource* IGXMLScanner::resolveSystemId(const XMLCh* const sysId) , fMemoryManager ); else - throw e; + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); } + else + { + if (fStandardUriConformant && urlTmp.hasInvalidChar()) + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); + srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); + } } return srcToFill; diff --git a/src/xercesc/internal/ReaderMgr.cpp b/src/xercesc/internal/ReaderMgr.cpp index afa3734dc..ef7a41bfb 100644 --- a/src/xercesc/internal/ReaderMgr.cpp +++ b/src/xercesc/internal/ReaderMgr.cpp @@ -544,6 +544,10 @@ XMLReader* ReaderMgr::createReader( const XMLCh* const sysId LastExtEntityInfo lastInfo; getLastExtEntityInfo(lastInfo); +// Keep this #if 0 block as it was exposing a threading problem on AIX. +// Got rid of the problem by changing XMLURL to not throw malformedurl +// exceptions. +#if 0 try { XMLURL urlTmp(lastInfo.systemId, expSysId.getRawBuffer(), fMemoryManager); @@ -576,6 +580,28 @@ XMLReader* ReaderMgr::createReader( const XMLCh* const sysId else throw e; } +#else + XMLURL urlTmp(fMemoryManager); + if ((!urlTmp.setURL(lastInfo.systemId, expSysId.getRawBuffer(), urlTmp)) || + (urlTmp.isRelative())) + { + if (!fStandardUriConformant) + srcToFill = new (fMemoryManager) LocalFileInputSource + ( + lastInfo.systemId + , expSysId.getRawBuffer() + , fMemoryManager + ); + else + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); + } + else + { + if (fStandardUriConformant && urlTmp.hasInvalidChar()) + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); + srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); + } +#endif } // Put a janitor on the input source @@ -653,29 +679,10 @@ XMLReader* ReaderMgr::createReader( const XMLCh* const baseURI LastExtEntityInfo lastInfo; getLastExtEntityInfo(lastInfo); - try - { - XMLURL urlTmp((!baseURI || !*baseURI) ? lastInfo.systemId : baseURI, expSysId.getRawBuffer(), fMemoryManager); - - if (urlTmp.isRelative()) - { - ThrowXMLwithMemMgr - ( - MalformedURLException - , XMLExcepts::URL_NoProtocolPresent - , fMemoryManager - ); - } - else { - if (fStandardUriConformant && urlTmp.hasInvalidChar()) - ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); - srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); - } - } - - catch(const MalformedURLException& e) + XMLURL urlTmp(fMemoryManager); + if ((!urlTmp.setURL((!baseURI || !*baseURI) ? lastInfo.systemId : baseURI, expSysId.getRawBuffer(), urlTmp)) || + (urlTmp.isRelative())) { - // Its not a URL, so lets assume its a local file name if non-standard uri is allowed if (!fStandardUriConformant) srcToFill = new (fMemoryManager) LocalFileInputSource ( @@ -684,8 +691,14 @@ XMLReader* ReaderMgr::createReader( const XMLCh* const baseURI , fMemoryManager ); else - throw e; + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); } + else + { + if (fStandardUriConformant && urlTmp.hasInvalidChar()) + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); + srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); + } } // Put a janitor on the input source diff --git a/src/xercesc/internal/SGXMLScanner.cpp b/src/xercesc/internal/SGXMLScanner.cpp index 77337007d..41f7b6fc3 100644 --- a/src/xercesc/internal/SGXMLScanner.cpp +++ b/src/xercesc/internal/SGXMLScanner.cpp @@ -3769,28 +3769,10 @@ void SGXMLScanner::resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* con ReaderMgr::LastExtEntityInfo lastInfo; fReaderMgr.getLastExtEntityInfo(lastInfo); - try + XMLURL urlTmp(fMemoryManager); + if ((!urlTmp.setURL(lastInfo.systemId, expSysId.getRawBuffer(), urlTmp)) || + (urlTmp.isRelative())) { - XMLURL urlTmp(lastInfo.systemId, expSysId.getRawBuffer()); - if (urlTmp.isRelative()) - { - ThrowXMLwithMemMgr - ( - MalformedURLException - , XMLExcepts::URL_NoProtocolPresent - , fMemoryManager - ); - } - else { - if (fStandardUriConformant && urlTmp.hasInvalidChar()) - ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); - srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); - } - } - - catch(const MalformedURLException& e) - { - // Its not a URL, so lets assume its a local file name if non-standard uri is allowed if (!fStandardUriConformant) srcToFill = new (fMemoryManager) LocalFileInputSource ( @@ -3799,8 +3781,14 @@ void SGXMLScanner::resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* con , fMemoryManager ); else - throw e; + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); } + else + { + if (fStandardUriConformant && urlTmp.hasInvalidChar()) + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); + srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); + } } // Put a janitor on the input source @@ -3929,27 +3917,10 @@ InputSource* SGXMLScanner::resolveSystemId(const XMLCh* const sysId) ReaderMgr::LastExtEntityInfo lastInfo; fReaderMgr.getLastExtEntityInfo(lastInfo); - try + XMLURL urlTmp(fMemoryManager); + if ((!urlTmp.setURL(lastInfo.systemId, expSysId.getRawBuffer(), urlTmp)) || + (urlTmp.isRelative())) { - XMLURL urlTmp(lastInfo.systemId, expSysId.getRawBuffer()); - if (urlTmp.isRelative()) - { - ThrowXMLwithMemMgr - ( - MalformedURLException - , XMLExcepts::URL_NoProtocolPresent - , fMemoryManager - ); - } - else { - if (fStandardUriConformant && urlTmp.hasInvalidChar()) - ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); - srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); - } - } - catch(const MalformedURLException& e) - { - // Its not a URL, so lets assume its a local file name if non-standard uri is allowed if (!fStandardUriConformant) srcToFill = new (fMemoryManager) LocalFileInputSource ( @@ -3958,8 +3929,14 @@ InputSource* SGXMLScanner::resolveSystemId(const XMLCh* const sysId) , fMemoryManager ); else - throw e; + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); } + else + { + if (fStandardUriConformant && urlTmp.hasInvalidChar()) + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); + srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); + } } return srcToFill; diff --git a/src/xercesc/internal/XMLScanner.cpp b/src/xercesc/internal/XMLScanner.cpp index 7f962e514..9ea479196 100644 --- a/src/xercesc/internal/XMLScanner.cpp +++ b/src/xercesc/internal/XMLScanner.cpp @@ -433,15 +433,6 @@ void XMLScanner::scanDocument( const XMLCh* const systemId) ); return; } - catch(const OutOfMemoryException&) - { - throw; - } - catch(...) - { - // Just rethrow this, since its not our problem - throw; - } Janitor<InputSource> janSrc(srcToUse); scanDocument(*srcToUse); @@ -472,28 +463,49 @@ bool XMLScanner::scanFirst( const XMLCh* const systemId // Create a temporary URL. Since this is the primary document, // it has to be fully qualified. If not, then assume we are just // mistaking a file for a URL. - XMLURL tmpURL(systemId, fMemoryManager); - if (tmpURL.isRelative()) { + XMLURL tmpURL(fMemoryManager); + if (XMLURL::parse(systemId, tmpURL)) { + if (tmpURL.isRelative()) { + if (!fStandardUriConformant) + srcToUse = new (fMemoryManager) LocalFileInputSource(systemId, fMemoryManager); + else { + // since this is the top of the try/catch, cannot call ThrowXMLwithMemMgr + // emit the error directly + MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_NoProtocolPresent, fMemoryManager); + fInException = true; + emitError + ( + XMLErrs::XMLException_Fatal + , e.getType() + , e.getMessage() + ); + return false; + } + } + else + { + if (fStandardUriConformant && tmpURL.hasInvalidChar()) { + MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_MalformedURL, fMemoryManager); + fInException = true; + emitError + ( + XMLErrs::XMLException_Fatal + , e.getType() + , e.getMessage() + ); + return false; + } + srcToUse = new (fMemoryManager) URLInputSource(tmpURL, fMemoryManager); + } + } + else { if (!fStandardUriConformant) - srcToUse = new (fMemoryManager) LocalFileInputSource(systemId, fMemoryManager); + srcToUse = new (fMemoryManager) LocalFileInputSource(systemId, fMemoryManager); else { // since this is the top of the try/catch, cannot call ThrowXMLwithMemMgr // emit the error directly - MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_NoProtocolPresent, fMemoryManager); - fInException = true; - emitError - ( - XMLErrs::XMLException_Fatal - , e.getType() - , e.getMessage() - ); - return false; - } - } - else - { - if (fStandardUriConformant && tmpURL.hasInvalidChar()) { - MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_MalformedURL, fMemoryManager); + // lazy bypass ... since all MalformedURLException are fatal, no need to check the type + MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_MalformedURL); fInException = true; emitError ( @@ -503,25 +515,6 @@ bool XMLScanner::scanFirst( const XMLCh* const systemId ); return false; } - srcToUse = new (fMemoryManager) URLInputSource(tmpURL, fMemoryManager); - } - } - catch(const MalformedURLException& e) - { - if (!fStandardUriConformant) - srcToUse = new (fMemoryManager) LocalFileInputSource(systemId, fMemoryManager); - else { - // since this is the top of the try/catch, cannot call ThrowXMLwithMemMgr - // emit the error directly - // lazy bypass ... since all MalformedURLException are fatal, no need to check the type - fInException = true; - emitError - ( - XMLErrs::XMLException_Fatal - , e.getType() - , e.getMessage() - ); - return false; } } catch(const XMLException& excToCatch) @@ -552,15 +545,6 @@ bool XMLScanner::scanFirst( const XMLCh* const systemId ); return false; } - catch(const OutOfMemoryException&) - { - throw; - } - catch(...) - { - // Just rethrow this, since its not our problem - throw; - } Janitor<InputSource> janSrc(srcToUse); return scanFirst(*srcToUse, toFill); @@ -1631,29 +1615,53 @@ Grammar* XMLScanner::loadGrammar(const XMLCh* const systemId // Create a temporary URL. Since this is the primary document, // it has to be fully qualified. If not, then assume we are just // mistaking a file for a URL. - XMLURL tmpURL(systemId, fMemoryManager); - if (tmpURL.isRelative()) + XMLURL tmpURL(fMemoryManager); + + if (XMLURL::parse(systemId, tmpURL)) { + + if (tmpURL.isRelative()) + { + if (!fStandardUriConformant) + srcToUse = new (fMemoryManager) LocalFileInputSource(systemId, fMemoryManager); + else { + // since this is the top of the try/catch, cannot call ThrowXMLwithMemMgr + // emit the error directly + MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_NoProtocolPresent, fMemoryManager); + fInException = true; + emitError + ( + XMLErrs::XMLException_Fatal + , e.getType() + , e.getMessage() + ); + return 0; + } + } + else + { + if (fStandardUriConformant && tmpURL.hasInvalidChar()) { + MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_MalformedURL, fMemoryManager); + fInException = true; + emitError + ( + XMLErrs::XMLException_Fatal + , e.getType() + , e.getMessage() + ); + return 0; + } + srcToUse = new (fMemoryManager) URLInputSource(tmpURL, fMemoryManager); + } + } + else { if (!fStandardUriConformant) srcToUse = new (fMemoryManager) LocalFileInputSource(systemId, fMemoryManager); else { // since this is the top of the try/catch, cannot call ThrowXMLwithMemMgr // emit the error directly - MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_NoProtocolPresent, fMemoryManager); - fInException = true; - emitError - ( - XMLErrs::XMLException_Fatal - , e.getType() - , e.getMessage() - ); - return 0; - } - } - else - { - if (fStandardUriConformant && tmpURL.hasInvalidChar()) { - MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_MalformedURL, fMemoryManager); + // lazy bypass ... since all MalformedURLException are fatal, no need to check the type + MalformedURLException e(__FILE__, __LINE__, XMLExcepts::URL_MalformedURL); fInException = true; emitError ( @@ -1663,25 +1671,6 @@ Grammar* XMLScanner::loadGrammar(const XMLCh* const systemId ); return 0; } - srcToUse = new (fMemoryManager) URLInputSource(tmpURL, fMemoryManager); - } - } - catch(const MalformedURLException& e) - { - if (!fStandardUriConformant) - srcToUse = new (fMemoryManager) LocalFileInputSource(systemId, fMemoryManager); - else { - // since this is the top of the try/catch, cannot call ThrowXMLwithMemMgr - // emit the error directly - // lazy bypass ... since all MalformedURLException are fatal, no need to check the type - fInException = true; - emitError - ( - XMLErrs::XMLException_Fatal - , e.getType() - , e.getMessage() - ); - return 0; } } catch(const XMLException& excToCatch) @@ -1712,15 +1701,6 @@ Grammar* XMLScanner::loadGrammar(const XMLCh* const systemId ); return 0; } - catch(const OutOfMemoryException&) - { - throw; - } - catch(...) - { - // Just rethrow this, since its not our problem - throw; - } } Janitor<InputSource> janSrc(srcToUse); diff --git a/src/xercesc/util/XMLURL.cpp b/src/xercesc/util/XMLURL.cpp index 738709396..bf2ceca17 100644 --- a/src/xercesc/util/XMLURL.cpp +++ b/src/xercesc/util/XMLURL.cpp @@ -221,8 +221,8 @@ XMLURL::XMLURL(const XMLCh* const baseURL , fHasInvalidChar(false) { try - { - setURL(baseURL, relativeURL); + { + setURL(baseURL, relativeURL); } catch(const OutOfMemoryException&) { @@ -424,6 +424,7 @@ XMLURL::XMLURL(const XMLURL& toCopy) : catch(...) { cleanup(); + throw; } } @@ -539,6 +540,35 @@ void XMLURL::setURL(const XMLCh* const baseURL } } +// this version of setURL doesn't throw a malformedurl exception +// instead it returns false when it failed (or when it would of +// thrown a malformedurl exception) +bool XMLURL::setURL(const XMLCh* const baseURL + , const XMLCh* const relativeURL + , XMLURL& xmlURL) +{ + cleanup(); + + // Parse our URL string + if (parse(relativeURL, xmlURL)) + { + // If its relative and the base is non-null and non-empty, then + // parse the base URL string and conglomerate them. + // + if (isRelative() && baseURL && *baseURL) + { + XMLURL basePart(fMemoryManager); + if (parse(baseURL, basePart) && conglomerateWithBase(basePart, false)) + { + return true; + } + } + else + return true; + } + return false; +} + void XMLURL::setURL(const XMLURL& baseURL , const XMLCh* const relativeURL) { diff --git a/src/xercesc/util/XMLURL.hpp b/src/xercesc/util/XMLURL.hpp index 2faaa4622..47ae27c37 100644 --- a/src/xercesc/util/XMLURL.hpp +++ b/src/xercesc/util/XMLURL.hpp @@ -175,8 +175,11 @@ public: const XMLURL& baseURL , const XMLCh* const relativeURL ); - - + // a version of setURL that doesn't throw malformed url exceptions + bool setURL( + const XMLCh* const baseURL + , const XMLCh* const relativeURL + , XMLURL& xmlURL); // ----------------------------------------------------------------------- // Miscellaneous methods // ----------------------------------------------------------------------- diff --git a/src/xercesc/validators/schema/TraverseSchema.cpp b/src/xercesc/validators/schema/TraverseSchema.cpp index 08bcfb003..44cc01ac7 100644 --- a/src/xercesc/validators/schema/TraverseSchema.cpp +++ b/src/xercesc/validators/schema/TraverseSchema.cpp @@ -6448,28 +6448,25 @@ InputSource* TraverseSchema::resolveSchemaLocation(const XMLCh* const loc, // the update resolveEntity accepting nameSpace, a schemImport could // pass a null schemaLocation) if (!srcToFill && loc) { - - try { - - XMLURL urlTmp(fSchemaInfo->getCurrentSchemaURL(), normalizedURI, fMemoryManager); - - if (urlTmp.isRelative()) { - ThrowXMLwithMemMgr(MalformedURLException, - XMLExcepts::URL_NoProtocolPresent, fMemoryManager); - } - else { - if (fScanner->getStandardUriConformant() && urlTmp.hasInvalidChar()) - ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); - srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); - } - } - catch(const MalformedURLException& e) { - // Its not a URL, so lets assume its a local file name if non-standard URI is allowed - if (!fScanner->getStandardUriConformant()) - srcToFill = new (fMemoryManager) LocalFileInputSource(fSchemaInfo->getCurrentSchemaURL(),normalizedURI, fMemoryManager); + XMLURL urlTmp(fMemoryManager); + if ((!urlTmp.setURL(fSchemaInfo->getCurrentSchemaURL(), normalizedURI, urlTmp)) || + (urlTmp.isRelative())) + { + if (!fScanner->getStandardUriConformant()) + srcToFill = new (fMemoryManager) LocalFileInputSource + ( fSchemaInfo->getCurrentSchemaURL() + , normalizedURI + , fMemoryManager + ); else - throw e; + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); } + else + { + if (fScanner->getStandardUriConformant() && urlTmp.hasInvalidChar()) + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_MalformedURL, fMemoryManager); + srcToFill = new (fMemoryManager) URLInputSource(urlTmp, fMemoryManager); + } } return srcToFill; -- GitLab