From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.help Subject: Re: Decoding URLs input Date: Sun, 4 Jul 2021 03:16:37 +0700 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27611"; mail-complaints-to="usenet@ciao.gmane.io" To: Yuri Khan , Help GNU Emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 03 22:17:16 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lzm4i-000703-9M for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 03 Jul 2021 22:17:16 +0200 Original-Received: from localhost ([::1]:38844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lzm4g-00034o-Ml for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 03 Jul 2021 16:17:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49284) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lzm4J-00034f-Sm for help-gnu-emacs@gnu.org; Sat, 03 Jul 2021 16:16:51 -0400 Original-Received: from mail-vs1-xe2d.google.com ([2607:f8b0:4864:20::e2d]:41898) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lzm4I-00046k-DC for help-gnu-emacs@gnu.org; Sat, 03 Jul 2021 16:16:51 -0400 Original-Received: by mail-vs1-xe2d.google.com with SMTP id c26so7872797vso.8 for ; Sat, 03 Jul 2021 13:16:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=V8LCOE4lcPlV2K+HNCk8DU5jYtmpjuIUKmNEUbdz5Cg=; b=b4cYyFxiPSYMGIqdhevKjHYf29D5mYdih2FArJrHjAwZ9dwArpJoy0OoGrc5+YPMiX bRgE53OlCPyqV/xnQZxG125+5aAIR0CrCNCsItp8GH0xU11/SjNKAbZmLKAFoBhmB4++ Fc6Yv7HD5xzyQ+KZ9yVMO4X0wUS+hH+jeUY/OiXwTpa+jyoBOEisYA73W8qG148btSMW GY82m6c44QEQDJIFTk5iYpgVLovlPZKx7B2yPcQMS2Wi+ocDXeRh82EK4nKxQV9T3Mfe SSealI9OuRL3tPrMulnMavgDn9Hg4ud7LcHVOfxOqtt1FMAxrjYH1rEk/hB2/UzfR0in dXag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=V8LCOE4lcPlV2K+HNCk8DU5jYtmpjuIUKmNEUbdz5Cg=; b=a/5rQv0e1ifApjRHH6pJKRDc9NDPENGwgWS/IPu0ZhybgVofN5Qg3amfaHUelR0ODE ojGmARZSlzboEWJI6n5bRwGEigYyO0iHtPvosEM07o7Q/KO0KJbadqLXFpSfgzBCgTcS Z3cmEec6EeppCOPlTwo5hEbj3NvvcJjU1pqZMEEQowVQgLK/lLxZZWHaeZMWfaAq57Hc S/MtO2YuZ8BZDR1R5fPm0Jqwcwrvt4hr+7kUrP1hehmpxkbJ6GwbzwWhGKaFDgs2nfju WdaSm+cpwGr59vFLsQHtDtS8z3mcz5FNpAKwnQMNW8zTi693pM7KEE+8VdCLg+6ZFZ5c QCfQ== X-Gm-Message-State: AOAM531NLxYX2Z4aIoGSZXQwTKy4UBd6E4QXfoJRzemAJVwmTpAiTRh5 Cm8IrS0E2XklaL8KXNHG20I2aD+OFO/Xt4dMQXY= X-Google-Smtp-Source: ABdhPJzotyzSP6zmynOi4LFoIeA224t14LlTbhiVJWqOxJtTh8p8X2kELwn84UYb+6XS3Pq18WKH6C7hCxJm2Y1tzOo= X-Received: by 2002:a67:8783:: with SMTP id j125mr5364657vsd.42.1625343409129; Sat, 03 Jul 2021 13:16:49 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::e2d; envelope-from=yurivkhan@gmail.com; helo=mail-vs1-xe2d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:131439 Archived-At: On Sun, 4 Jul 2021 at 02:20, Jean Louis wrote: > From docstring of `url-unhex-string' I did not expect it would give > just bytes back, then that should be IMHO described there, I am not > sure really. Maybe it is assumed for programmer to know that. I just fed it some percent-encoded sequences that I knew would result in invalid UTF-8 when decoded. If it were doing a full decode, I expected it to signal an error. It didn=E2=80=99t. > The docstring is poor, it says like: "Remove %XX embedded spaces, etc in = a > URL." -- with "remove" I don't expect converting UTF-8 into bytes. Yeah, that is bad. If I see =E2=80=9Cremove %xx=E2=80=9D in a docstring, I = expect (string=3D (f "Hello%20World") "HelloWorld"). > I am now solving the issue that spaces are converted to plus sign and > that I have to convert + signs maybe before: > (decode-coding-string (url-unhex-string "Hello+There") 'utf-8) > but maybe not before, maybe I leave it and convert later. You have to replace them before percent-decoding. If you try it after percent-decoding, you will not be able to distinguish a + that encodes a space from a + that you just decoded from %2B. Luckily, spaces never occur in a valid encoded query string; if they did and had some meaning, you=E2=80=99d have to decode + *at the same time* as %xx. Here, have some test cases: "Hello+There%7DWorld" =E2=86=92 "Hello There}World" "Hello%2BThere%7DWorld" =E2=86=92 "Hello+There}World" By the way, you=E2=80=99re in for some unspecified amount of pain by trying= to implement a web application without a framework. (And by a framework I mean a library that would give you well-tested means to encode/decode URL parts, HTTP headers, gzipped request/response bodies, base64, quoted-printable, application/x-www-form-urlencoded, multipart/form-data, json, =E2=80=A6) CGI is not nearly as simple as it initially appears to be when you read a hello-cgi-world tutorial.