Page 1 of 1

Code download gives wrong filename

Posted: 25 Jan 2015, 17:31
by lexikos
It appears that when there are multiple code blocks, the filename of the first one (if any) is used the download link downloads the first code block, even if that one doesn't have a download link. If I click the download link below, I get Untitled.txt (Test) on Chrome 42 and IE11:

Code: Select all

Test2

Code: Select all

Test
Manually adjusting the URL from part=1 to part=2 gives me the correct code block in this case.

Re: Code download gives wrong filename

Posted: 25 Jan 2015, 19:47
by joedf
Looks like TLM is working on it right now ;)

Re: Code download gives wrong filename

Posted: 25 Jan 2015, 20:49
by TLM
Simplified some unnecessarily complicated preg.
Seems to be working.

Re: Code download gives wrong filename

Posted: 25 Jan 2015, 23:53
by joedf
great! what was the fix in general?
it would be great to know for future purposes. it happened to me once where i needed to know what i did before and luckily i had it posted somewhere.. ;)

Edit i think it was simply the regex going bezerk?

Code: Select all

// preg updated by TLM
	preg_match_all(	"#\s+file=(.*?):"
					. $post_data[$col_bbcode_uid] . "\](.*?)\[/code:"
					. $post_data[$col_bbcode_uid] . "\]#msi"
					, $post_data[$col_msg_text]
					, $code_data);

Re: Code download gives wrong filename

Posted: 26 Jan 2015, 01:59
by TLM
I left a copy of the original preg above the update in the script plus a backup script appended with _ in the same dir :)

I used sample values returned for $post_data[$col_msg_text], extracted/substituted values/variables for $post_data[$col_bbcode_uid]
and tested the original capturing sub-pattern matches in $code_data[ 1 ][ 0 ] and $code_data[ 2 ][ 0 ].
Under the existing pattern, $code_data[ 2 ][ 0 ] didn't return anything ( when the code blocks are named as lexikos stated ), which was the issue.

I just simplified the approach of obtaining the capturing sub-pattern matches and stress tested it.
(wish there was an easier/cleaner way to debug though)

Re: Code download gives wrong filename

Posted: 26 Jan 2015, 09:00
by joedf
Nice! Yes I saw the console.log() haha, but anyhow it looks it sufficient ;)
Thanks for sharing, but I wonder why this happened now...