Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94741 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69644 invoked from network); 28 Jul 2016 18:24:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jul 2016 18:24:58 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.217.170 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.217.170 mail-ua0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:36176] helo=mail-ua0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 45/90-64416-9FD4A975 for ; Thu, 28 Jul 2016 14:24:57 -0400 Received: by mail-ua0-f170.google.com with SMTP id j59so45764687uaj.3 for ; Thu, 28 Jul 2016 11:24:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=zYLWr3fY62QS3hodeCJoKN6vMuxsvTiQdHhJoBJi5II=; b=X/RphkBrdkColJL54kTrZ3Q6Hxf6lZTwLQVQc5L44nSpPvI5q9fQcB+u8gTNvle3Hf jfiu7ThV6I/umzDfbwItF2vFchtM5vmRUOXfBUZWmdT6O2FsySfX3StLZZdLcdgapTFt JwEDT8BtGPqoZlwU3Dml3ijvAqd+sd/xy0WizVpo8x0yHbrw9xGx2eisVPsrFpFHt/z8 7nYkY+i64t4o/0aRYOS+DazdemMTxl6xp0+SyP+Ik6zpNCO4UXS86t9enwboVZ0lzofw et1w92OTD44ho+5jnh/zKr0V/t7aWQgt79dvZ+iq0ejNc36iSg0R2M/dB5sNhhC/HbXX Ph+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=zYLWr3fY62QS3hodeCJoKN6vMuxsvTiQdHhJoBJi5II=; b=B3tWLv04Y66cAhPzfPijNkWm5aFTx8C6o8u3KZnONnTUaZU927YUMPWk502+E6rJ0X 1urM3HyiJ9GSOL5MppBNDjFWuCi/nTJkRuYoWKga9ezAf8ueUG9tx82TzvN3HTAmI2Yv Cab99yRbMO9rhZvaya/RkMgbxQr+Ggj4CYT9q2wJNyuUvtLwXltD1L16MsAvTZasFOqP geEbFWJMXB00P7TWzMsJBWbJK9xAYXG/dZvbZfe9OFELIDTw/i4I/VeyDftsp+XBWVdX YQMwt/Fnc2d66XXOv01hbBUPuuMxscKXZp6pid1DFYoUgOInHMB7hCTfvUHTe4PZ29V6 Srjg== X-Gm-Message-State: AEkoout9ugvZ30OfXZpyYYjgoAZ8PgYU4eWG7q29UdMlzevyOSO/62hBorUgXREjgqkxeS1ep3KUPCQAX77FDg== X-Received: by 10.176.65.71 with SMTP id j65mr16350368uad.103.1469730294687; Thu, 28 Jul 2016 11:24:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.153.195 with HTTP; Thu, 28 Jul 2016 11:24:53 -0700 (PDT) In-Reply-To: References: <933449d0-90c2-0d7a-cb80-a171289d8286@texthtml.net> <20160724145557.D52C31A80BBD@dd1730.kasserver.com> <6cfac572-9982-87f8-5a55-9213d978cde9@gmx.de> <20160724162103.BC5741A83512@dd1730.kasserver.com> <20160724172131.675AC1A800B0@dd1730.kasserver.com> <9bc0db6a-fa19-5f87-0e82-3702dcb34254@gmx.de> <20160727224510.7B80C1A80358@dd1730.kasserver.com> <20160728093917.5DCC51A82392@dd1730.kasserver.com> Date: Thu, 28 Jul 2016 20:24:53 +0200 Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary=94eb2c1247082182380538b64035 Subject: Re: [PHP-DEV] [RFC] New operator for context-dependent escaping From: rasmus@mindplay.dk (Rasmus Schultz) --94eb2c1247082182380538b64035 Content-Type: text/plain; charset=UTF-8 Just a thought, but I can't help thinking that "improved escape facilities and syntax" are a mere patch for a more than superficial problem. The problem of differentiating HTML strings, which to not require escaping, from other string, which do, could actually be viewed as a deeper problem, which is the inability to tell string types apart. I mean, there are many different types of strings - text, HTML, URLs, e-mail addresses, UUIDs, etc. The surface problem is that user has to know whether she's dealing with a text or HTML string. But you could view that as a symptom of the inability to designate, at the source, what type of string you're providing. For example, compare this: class ProductView { /** @var string product name as plain text, remember to escape this */ public $product_name; /** @var string product description as HTML, do not escape this */ public $description; } With something (completely ficticious) like, say: typedef HTML extends string; class ProductView { /** @var string product name */ public $product_name; /** @var HTML product description */ public $description; } And a more intelligent escape function, like: function html($str) { return $str instanceof HTML ? $str : htmlspecialchars($str); } This removes one source of error - the user can now safely apply the html() function to any string, without having to know if the string is just a string or HTML. (yeah, I know about the $double_encode switch for htmlspecialchars() but that's actually just another example of a work-around to the same, deeper problem.) A feature like this is more general-purpose, and potentially solves many other related problems, such as recognizing the difference between ints or UUIDs with different intent, e.g. being identifiers for different entities. My main point is that the proposed feature attempts to fix a problem that applies to one use-case - templates - whereas looking deeper and fixing problems, or adding features that work across the entire language for many use-cases, tends to add more value and, in the long run, less complexity. Usually, a deeper, more general feature will enable users to create solutions, rather than fixing each of their problems with surface solutions, one at a time, until the language becomes a crazy colorful cacophony of solutions, rather than tools to *create* solutions. Just my perspective... On Thu, Jul 28, 2016 at 11:48 AM, Rowan Collins wrote: > On 28/07/2016 10:39, Thomas Bley wrote: > >> creating an e() function can be a BC break if people already have an e() >> function in their code. >> The name e is ambiguous to me, is it escape, error, encrypt? >> >> You are free to provide a better rfc, but having e() being optional will >> also make security optional. >> > > I wrote an entire e-mail setting out what I think should be the aims of > the feature, and you've picked on a single sentence that said that an e() > function would fulfil *most* of those aims. At no point did I say "an e() > function is the perfect solution". You are attacking a straw man. > > I'm not going to get into a back and forth on what "optional" means, > either. I've stated what I think is important, and will leave it there. > > > Regards, > -- > Rowan Collins > [IMSoP] > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --94eb2c1247082182380538b64035--