Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5Gkl-00020o-0i for pgsql-hackers@arkaria.postgresql.org; Sat, 16 Mar 2019 21:22:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h5Gkj-0003Xf-9j for pgsql-hackers@arkaria.postgresql.org; Sat, 16 Mar 2019 21:22:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5Gkj-0003WB-0Y for pgsql-hackers@lists.postgresql.org; Sat, 16 Mar 2019 21:22:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5Gkc-0005HL-ON for pgsql-hackers@postgresql.org; Sat, 16 Mar 2019 21:22:00 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x2GLLCMk024204; Sat, 16 Mar 2019 17:21:12 -0400 From: Tom Lane To: Chapman Flack cc: Ryan Lambert , pgsql-hackers@postgresql.org Subject: Re: Fix XML handling with DOCTYPE In-reply-to: <5C8D6681.4070504@anastigmatix.net> References: <5C8D5D16.7090206@anastigmatix.net> <23319.1552769738@sss.pgh.pa.us> <5C8D6681.4070504@anastigmatix.net> Comments: In-reply-to Chapman Flack message dated "Sat, 16 Mar 2019 17:11:29 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <24202.1552771272.1@sss.pgh.pa.us> Date: Sat, 16 Mar 2019 17:21:12 -0400 Message-ID: <24203.1552771272@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Chapman Flack writes: > On 03/16/19 16:55, Tom Lane wrote: >> What do you think of the idea I just posted about parsing off the DOCTYPE >> thing for ourselves, and not letting libxml see it? > The principled way of doing that would be to pre-parse to find a DOCTYPE, > and if there is one, leave it there and parse the input as we do for > 'document'. Per XML, if there is a DOCTYPE, the document must satisfy > the 'document' syntax requirements, and per SQL/XML:2006-and-later, > 'content' is a proper superset of 'document', so if we were asked for > 'content' and can successfully parse it as 'document', we're good, > and if we see a DOCTYPE and yet it incurs a parse error as 'document', > well, that's what needed to happen. Hm, so, maybe just (1) always try to parse as document. If successful, we're done. (2) otherwise, if allowed by xmloption, try to parse using our current logic for the CONTENT case. This avoids adding any new assumptions about how libxml acts, which is what I was hoping to achieve. One interesting question is which error to report if both (1) and (2) fail. regards, tom lane