Jump to content

Module talk:DecodeEncode: Difference between revisions

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Content deleted Content added
Line 123: Line 123:
* Phabricator {{phab|T328840}} did not gain traction. Would be mw-level, not this module.
* Phabricator {{phab|T328840}} did not gain traction. Would be mw-level, not this module.
:-[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 06:22, 16 February 2023 (UTC)
:-[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 06:22, 16 February 2023 (UTC)

== Template-protected edit request on 16 February 2023 ==

{{edit template-protected|Module:DecodeEncode|answered=no}}

* '''Please copy all code''' from [[:module:DecodeEncode/sandbox]] into [[:module:DecodeEncode]] ({{diffsandbox|Module:DecodeEncode}})
:''Issue:'' bad decoding of HTML entity <code>&amp;epsi;</code> {{nay}}
:re {{unichar|03B5|GREEK SMALL LETTER EPSILON|html=}}
:''Change:'' fix by replacing with entity <code>&amp;epsilon;</code> {{aye}} before applying <code>decode()</code>. See {{slink||Workaround B}} for code diff & backgrounds; minor comment change
:''Discussion:'' (1) reported at {{phab|T328840}}, no responses (mw-level); (2) [[#U+03B5|bug report]] here not challenged
:''Testcases:'' See {{slink||testcases EPSILON}}.
:[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 06:49, 16 February 2023 (UTC)

Revision as of 06:49, 16 February 2023

Bug report: bad decoding of U+03B5 ε (epsilon)

About U+03B5 ε GREEK SMALL LETTER EPSILON (&epsi; &epsilon;)

  • Issue: after resolving HTML entity &epsilon; by mw.text.decode(), the plain character is not found by mw.ustring.gsub(). No issue with alternative HTML entity &epsi;. &epsi; good, &epsilon; bad.
Report limitations: Original report and bug reproduction is at enwiki Module talk:DecodeEncode, from where en:module:DecodeEncode and en:module:String are used live. At phabricator pseudocode may be used and some "results" may be hardcoded. In-text the escape &amp; is used, not in-function. Lua patterns not used ("no %").
  • To reproduce:
1. Create research string:
X&epsi;1X&epsilon;2X (shows live and unedited as: Xε1Xε2X)
2. Render the string by decode() (as inner function)
3. then on rendered result use gsub() to replace plain character ε → E: (as outer function)
mw.ustring.gsub( s=(mw.text.decode( s=X&epsi;1X&epsilon;2X, decodeNamedEntities=true ) ), pattern=ε, repl=E ) [is pseudo-code, see note. 21:10, 7 February 2023 (UTC)]
4. Result3 (s&r pattern use ε from Xε1X):
XE1XE2X
5. Result4 (s&r pattern use ε from Xε2X):
XE1XE2X
  • Expected: XE1XE2X (only one character ε exists)
{{#invoke:String|replace|source={{#invoke:DecodeEncode|decode|s=X&epsi;1X&epsilon;2X}}|pattern=ε|replace=E|plain=true}}
→ XE1XE2X
-DePiep (talk) 21:10, 7 February 2023 (UTC)Reply

Workaround A, ad hoc

Workaround A, ad hoc: add innermost function to first replace in the research string &epsilon; → &epsi;:

A1: {{#invoke:String|replace|source={{#invoke:DecodeEncode|decode|s={{#invoke:String|replace|source=X&epsi;1X&epsilon;2X|pattern=&epsilon;|replace=&epsi;|plain=true}}}}|pattern=ε|replace=E|plain=true}} →
XE1XE2X

Workaround B, in module (THIN SPACE example)

Workaround B: early in :en:module:DecodeEncode, replace &epsilon; → &epsi;

About THIN SPACE: it looks like character U+2009 THIN SPACE (&thinsp; &ThinSpace;) has a samilar issue. &ThinSpace; good, &thinsp; bad.

Currently in code:

function p._decode( s, subset_only )
	local ret = nil;
    s = mw.ustring.gsub( s, '&thinsp;', '&ThinSpace;' ) -- Workaround for bug: &ThinSpace; gets properly decoded in decode, but &thinsp; doesn't.
	ret = mw.text.decode( s, not subset_only )
	return ret
end

In en:module:DecodeEncode/sandbox, I have coded a similar handling of EPSILON:

module:DecodeEncode, module:DecodeEncode/sandbox diff
function p._decode( s, subset_only )
	local ret = nil;
	-- U+2009 THIN SPACE: workaround for bug: HTML entity &thinsp; is decoded incorrect. Entity &ThinSpace; gets decoded properly
	s = mw.ustring.gsub( s, '&thinsp;', '&ThinSpace;' )
	-- U+03B5 ε GREEK SMALL LETTER EPSILON: workaround for bug (phab:T328840): HTML entity &epsilon; is decoded incorrect for gsub(). Entity &epsi; gets decoded properly
	s = mw.ustring.gsub( s, '&epsilon;', '&epsi;' )
	ret = mw.text.decode( s, not subset_only )
	return ret
end
  • /sandbox tests:
B. {{#invoke:String|replace|source={{#invoke:DecodeEncode/sandbox|decode|s=X&epsi;1X&epsilon;2X}}|pattern=ε|replace=E|plain=true}}
B1. ResultB1 (s&r pattern use ε from Xε1X): XE1XE2X
B2. ResultB2 (s&r pattern use ε from Xε2X): XE1XE2X

I propose to edit the module along this way.

Workaround C (mw, Lua)

Changes in mw, Lua: I have not idea.

testcases EPSILON

EPSILON ε ⟨&epsi;⟩ error & fix proposal (16 Feb 2023)
1 2 3 4 5 6
id entity code plain mod:.. decode(&entity;) replace(decode(..)) with E
pattern=hardcoded ⟨ε⟩ from plain
(s=&entity;)
(s=checkstring)
mod:..decode/sandbox
checkstring X&epsi;1X&epsilon;2X >Xε1Xε2X< >Xε1Xε2X<
EPSI &epsi; >ε< >ε< E
XE1XE2X
E
XE1XE2X
EPSILON &epsilon; >ε< >ε< E
XE1XE2X
Red X
E
XE1XE2X
Similar fix as U+2009   THIN SPACE (&thinsp;, &ThinSpace;) has (though original cause bug may be different for THIN SPACE).
  • Phabricator T328840 did not gain traction. Would be mw-level, not this module.
-DePiep (talk) 06:22, 16 February 2023 (UTC)Reply

Template-protected edit request on 16 February 2023

Issue: bad decoding of HTML entity &epsi; Red X
re U+03B5 ε GREEK SMALL LETTER EPSILON (&epsi;, &epsilon;)
Change: fix by replacing with entity &epsilon; Green tick before applying decode(). See § Workaround B for code diff & backgrounds; minor comment change
Discussion: (1) reported at T328840, no responses (mw-level); (2) bug report here not challenged
Testcases: See § testcases EPSILON.
DePiep (talk) 06:49, 16 February 2023 (UTC)Reply