Module talk:Wd/Archive 1: Difference between revisions

Content deleted Content added
m Archiving 1 discussion(s) from Module talk:Wd) (bot
m Archiving 1 discussion(s) from Module talk:Wd) (bot
Line 1,221:
Please copy the contents of [[Module:wd/sandbox|the module sandbox]] to [[Module:wd|the main module page]]. The explanation of the changes is above. [[User:Janhrach|Janhrach]] ([[User talk:Janhrach|talk]]) 17:17, 23 June 2023 (UTC)
: {{done}} [[User:Pppery|* Pppery *]] [[User talk:Pppery|<sub style="color:#800000">it has begun...</sub>]] 01:55, 24 June 2023 (UTC)
 
== gsub pattern bug? ==
 
I was editing the module on another wiki and the editor warned me of an invalid escape sequence in
:<code>mw.ustring.gsub(datavalue['amount'], "^\+(.+)$", "%1")</code>
 
If I'm reading [https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Character_class the manual] correctly, the escape character is indeed %, not \. So <code>\+</code> should be replaced with <code>%+</code> (twice). [[User:Ponor|Ponor]] ([[User talk:Ponor|talk]]) 21:44, 25 May 2023 (UTC)
:You are probably correct but try these in the debug console:
:#<code>=string.gsub ('+something', "^\+(.+)$", "%1")</code> → something 1
:#<code>=string.gsub ('+something', "^+(.+)$", "%1")</code> → something 1
:#<code>=string.gsub ('+something', "^%+(.+)$", "%1")</code> → something 1
:Number three is probably the 'most' correct. I expect that number 2 works because is doesn't make sense to quantify the zero-width assertion <code>^</code>. Does number 1 work because of a flaw? because <code>\</code> is a character-in-a-string-escape-character (similar to: <code>local pear_type_str = 'D\'Anjou'</code>)? I don't actually know.
:—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 22:25, 25 May 2023 (UTC)
::I'm only guessing (and mostly repeating your ideas), but it could be that whatever parses that pattern-string first reduces #1 to #2 (there's a mention of something similar with \ddd), which then works because + means nothing but + after that ^. I'd still fix this, so people don't get confused by those two error messages (❌). [[User:Ponor|Ponor]] ([[User talk:Ponor|talk]]) 23:47, 25 May 2023 (UTC)
:::What {{tq|error messages}}?
:::—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 23:49, 25 May 2023 (UTC)
::::Start editing, next to line number 405 there's gonna be a red square that'll show the error message. [[User:Ponor|Ponor]] ([[User talk:Ponor|talk]]) 09:39, 26 May 2023 (UTC)
:::{{ping|Ponor}} I've investigated this a bit and I've come to the same conclusion as you. But is using <code>gsub</code> really necessary? <code>tonumber</code> doesn't seem to have problems with <code>+</code> at the beginning of its input, so I think that removing the plus sign is unnecessary. [[User:Janhrach|Janhrach]] ([[User talk:Janhrach|talk]]) 09:49, 25 June 2023 (UTC)
::::@[[User:Janhrach|Janhrach]], I agree. It's just hard to tell what made people put it there, maybe things did not work back then. Which is not the reason to keep it there forever. [[User:Ponor|Ponor]] ([[User talk:Ponor|talk]]) 15:26, 26 June 2023 (UTC)
:::::I've fixed the error in the sandbox by removing <code>gsub</code>. After that, another error of nearly the same kind was shown by the editor on the line 875, which I fixed by replacing <code>\</code> whith <code>%</code>. I have a sample output in [[User:Janhrach/sandbox|my sandbox]]. I've verified both of the examples execute the altered code lines and that output is also correct when <code>+</code> shouldn't be stripped from the input. If there is no problem with my changes, I'll make an edit request soon. [[User:Janhrach|Janhrach]] ([[User talk:Janhrach|talk]]) 11:56, 27 June 2023 (UTC)
 
=== Edit request on 30 June 2023 ===
 
{{edit template-protected|Module:Wd|answered=yes}}
Please copy the contents of [[Module:wd/sandbox|the module sandbox]] to [[Module:wd|the main module page]]. The explanation of the changes is above. For context, read the whole discussion please. [[User:Janhrach|Janhrach]] ([[User talk:Janhrach|talk]]) 13:58, 30 June 2023 (UTC)
:{{done}}<!-- Template:ETp --> &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 14:14, 30 June 2023 (UTC)
::Thank you. [[User:Janhrach|Janhrach]] ([[User talk:Janhrach|talk]]) 14:14, 30 June 2023 (UTC)