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 1h5Gah-0001P4-MR for pgsql-hackers@arkaria.postgresql.org; Sat, 16 Mar 2019 21:11:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h5Gag-0003FF-GH for pgsql-hackers@arkaria.postgresql.org; Sat, 16 Mar 2019 21:11:38 +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 1h5Gag-0003DG-8L for pgsql-hackers@lists.postgresql.org; Sat, 16 Mar 2019 21:11:38 +0000 Received: from anastigmatix.net ([68.171.219.55]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5Gae-00053X-9U for pgsql-hackers@postgresql.org; Sat, 16 Mar 2019 21:11:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=anastigmatix.net; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:Cc:References:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ziWbkbirrFV/qrdtspXfTMuvXpWG//RsMIFYqwupi68=; b=LbvvrM0tvxM7ctYS0c/x3/uekm wPZ2tsydU2IZatzsAwIT934foV9tQEDD7BdBC6vRKquTneXrvFpb6L54Tbn/VgGa+v1Au8Ktmx8Tt VrvhPK9lfnyjlqRFp1/ZXyFVX+HV8WngersS7TGYNOKDoabuw5eUew/CXbQ3NJHwS7vfvnGHGJHk8 uTL2fZAMUkB9MofDs7PAQ+/hiMVlfpwYdIbtKD2BHbr1jljsmrZbVJfEHFYlzh/zCdPbxXg6jnpdf kMVhcslx+pK0vZAZARojsIIDDnDBdK9jPUhnpmlXnFqDgVysR0RJb6ROqhQtitt5S1eAiMJZSQMg0 ZMm6dzog==; Received: from [184.19.63.78] (port=45639) by bay.acenet.us with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.91) (envelope-from ) id 1h5GaX-00G1Pg-RV; Sat, 16 Mar 2019 17:11:34 -0400 Subject: Re: Fix XML handling with DOCTYPE To: Tom Lane References: <5C8D5D16.7090206@anastigmatix.net> <23319.1552769738@sss.pgh.pa.us> Cc: Ryan Lambert , pgsql-hackers@postgresql.org From: Chapman Flack X-Enigmail-Draft-Status: N1110 Message-ID: <5C8D6681.4070504@anastigmatix.net> Date: Sat, 16 Mar 2019 17:11:29 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: <23319.1552769738@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-OutGoing-Spam-Status: No, score=-95.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bay.acenet.us X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - anastigmatix.net X-Get-Message-Sender-Via: bay.acenet.us: authenticated_id: chap@anastigmatix.net X-Authenticated-Sender: bay.acenet.us: chap@anastigmatix.net X-Source: X-Source-Args: X-Source-Dir: X-From-Rewrite: unmodified, already matched List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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. The DOCTYPE can appear arbitrarily far in, but the only things that can precede it are the XML decl, whitespace, XML comments, and XML processing instructions. None of those things nest, so the preceding stuff makes a regular language, and a regular expression that matches any amount of that stuff ending in