Code download gives wrong filename

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Code download gives wrong filename

Re: Code download gives wrong filename

Post by joedf » 26 Jan 2015, 09:00

Nice! Yes I saw the console.log() haha, but anyhow it looks it sufficient ;)
Thanks for sharing, but I wonder why this happened now...

Re: Code download gives wrong filename

Post by TLM » 26 Jan 2015, 01:59

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

Post by joedf » 25 Jan 2015, 23:53

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

Post by TLM » 25 Jan 2015, 20:49

Simplified some unnecessarily complicated preg.
Seems to be working.

Re: Code download gives wrong filename

Post by joedf » 25 Jan 2015, 19:47

Looks like TLM is working on it right now ;)

Code download gives wrong filename

Post by lexikos » 25 Jan 2015, 17:31

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.

Top