From owner-svn-src-head@freebsd.org Sat Jun 13 14:11:02 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A83E03397AD; Sat, 13 Jun 2020 14:11:02 +0000 (UTC) (envelope-from yuripv@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49kfdf41hkz46dY; Sat, 13 Jun 2020 14:11:02 +0000 (UTC) (envelope-from yuripv@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 84F5D1C6B6; Sat, 13 Jun 2020 14:11:02 +0000 (UTC) (envelope-from yuripv@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 05DEB2Vj097869; Sat, 13 Jun 2020 14:11:02 GMT (envelope-from yuripv@FreeBSD.org) Received: (from yuripv@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 05DEB2mP097868; Sat, 13 Jun 2020 14:11:02 GMT (envelope-from yuripv@FreeBSD.org) Message-Id: <202006131411.05DEB2mP097868@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: yuripv set sender to yuripv@FreeBSD.org using -f From: Yuri Pankov Date: Sat, 13 Jun 2020 14:11:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362148 - head/contrib/nvi/common X-SVN-Group: head X-SVN-Commit-Author: yuripv X-SVN-Commit-Paths: head/contrib/nvi/common X-SVN-Commit-Revision: 362148 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Jun 2020 14:11:02 -0000 Author: yuripv Date: Sat Jun 13 14:11:02 2020 New Revision: 362148 URL: https://svnweb.freebsd.org/changeset/base/362148 Log: nvi: fallback to ISO8859-1 as last resort Current logic of using user's locale encoding that is UTF-8 doesn't make much sense if we already failed the looks_utf8() check and skipped encoding set using "fileencoding" as being UTF-8 as well; fallback to ISO8859-1 in that case. Reviewed by: Zhihao Yuan Differential Revision: https://reviews.freebsd.org/D24919 Modified: head/contrib/nvi/common/exf.c Modified: head/contrib/nvi/common/exf.c ============================================================================== --- head/contrib/nvi/common/exf.c Sat Jun 13 09:16:07 2020 (r362147) +++ head/contrib/nvi/common/exf.c Sat Jun 13 14:11:02 2020 (r362148) @@ -1237,7 +1237,10 @@ file_encinit(SCR *sp) } /* - * Detect UTF-8 and fallback to the locale/preset encoding. + * 1. Check for valid UTF-8. + * 2. Check if fallback fileencoding is set and is NOT UTF-8. + * 3. Check if user locale's encoding is NOT UTF-8. + * 4. Use ISO8859-1 as last resort. * * XXX * A manually set O_FILEENCODING indicates the "fallback @@ -1246,9 +1249,13 @@ file_encinit(SCR *sp) */ if (looks_utf8(buf, blen) > 1) o_set(sp, O_FILEENCODING, OS_STRDUP, "utf-8", 0); - else if (!O_ISSET(sp, O_FILEENCODING) || - !strcasecmp(O_STR(sp, O_FILEENCODING), "utf-8")) + else if (O_ISSET(sp, O_FILEENCODING) && + strcasecmp(O_STR(sp, O_FILEENCODING), "utf-8") != 0) + /* Use fileencoding as is */ ; + else if (strcasecmp(codeset(), "utf-8") != 0) o_set(sp, O_FILEENCODING, OS_STRDUP, codeset(), 0); + else + o_set(sp, O_FILEENCODING, OS_STRDUP, "iso8859-1", 0); conv_enc(sp, O_FILEENCODING, 0); #endif