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 1h5w2g-0002lg-1x for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Mar 2019 17:27:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h5w2e-0000Bd-N2 for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Mar 2019 17:27:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5w2d-0008O0-VI for pgsql-hackers@lists.postgresql.org; Mon, 18 Mar 2019 17:27:16 +0000 Received: from anastigmatix.net ([68.171.219.55]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5w2b-0002yf-2l for pgsql-hackers@postgresql.org; Mon, 18 Mar 2019 17:27:14 +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=WiuYAYqrPBUWJD+iRD9jiUBxTnhxVX6m/Y+bLuTTDFk=; b=iPL5Y8yjnnrNz3r5CvFPH9IypC zbBZnpBpi6HU77bekrNibBOkPX/Hach427YKQlRWRZ92nCBAnNfZkC62I2mdqLOCrFm9D7nirPF9c +X9HXGgHtmF7RjKmrmtokXd23XMGAxM4gsw/xeu/fjSbNsvHOSYXwKfODMosmSuc1iulubj0fnln1 T53OWVsavvSJh9MdC5o6NNNokvmZ+ctQpRyygcOOncIyWnPdqe5xiI1tj+MGe8KvgCl7qyUgbtMtL QhfI2xMaRlPw7XhahVsnI8Y+gk+eHWBBCPsNsQTnysDaKkhAdCZRkYtHhB13DPhc+9WGx9Gdtajbc yuBg2spg==; Received: from [184.19.63.78] (port=46986) by bay.acenet.us with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.91) (envelope-from ) id 1h5w2Z-00GPsz-8G; Mon, 18 Mar 2019 13:27:11 -0400 Subject: Re: Fix XML handling with DOCTYPE To: Tom Lane References: <5C8D5D16.7090206@anastigmatix.net> <23319.1552769738@sss.pgh.pa.us> <5C8D6681.4070504@anastigmatix.net> <24203.1552771272@sss.pgh.pa.us> <5C8D79AF.7010204@anastigmatix.net> <5146.1552837534@sss.pgh.pa.us> <5C8E7FC0.8040401@anastigmatix.net> <31664.1552842991@sss.pgh.pa.us> <5C8E8E2F.9050600@anastigmatix.net> <25228.1552849567@sss.pgh.pa.us> <5C8ECAA4.3090301@anastigmatix.net> Cc: Ryan Lambert , pgsql-hackers@postgresql.org From: Chapman Flack X-Enigmail-Draft-Status: N1110 Message-ID: <5C8FD4EE.7090107@anastigmatix.net> Date: Mon, 18 Mar 2019 13:27:10 -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: <5C8ECAA4.3090301@anastigmatix.net> 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 There might be too many different email threads on this with patches, but in case it went under the radar, xml-content-2006-3.patch appeared in my previous message on this thread[1]. It is based on a simple pre-check of the prefix of the input, determining which form of parse to apply. That may or may not be simpler than parse- once-save-error-parse-again-report-first-error, but IMV it's a more direct solution and clearer (the logic is clearly about "how do I determine the way this input should be parsed?" which is the problem on the table, rather than "how should I save and regurgitate this libxml error?" which turns the problem on the table to a different one). I decided, for a first point of reference, to wear the green eyeshade and write a pre-check that exactly implements the applicable rules. That gives a starting point for simplifications that are probably safe. For example, a bunch of lines at the end have to do with verifying the content inside of a processing-instruction, after finding where it ends. We could reasonably decide that, for the purpose of skipping it, knowing where it ends is enough, as libxml will parse it next and report any errors anyway. That would slightly violate my intention of sending input to (the parser that wasn't asked for) /only/ when it's completely clear (from the prefix we've seen) that that's where it should go. The relaxed version could do that in completely-clear cases and cases with an invalid PI ahead of what looks like a DTD. But you'd pretty much expect both parsers to produce the same message for a bad PI anyway. That made me just want to try it now, and--surprise!--the messages from libxml are not the same. So maybe I would lean to keeping the green-eyeshade rules in the test, if you can stomach them, but I would understand taking them out. Regards, -Chap [1] https://www.postgresql.org/message-id/5C8ECAA4.3090301@anastigmatix.net