David Kahn
2010-Dec-10 04:40 UTC
Rails/ruby seems to be interpreting the content in "render :file" request
Got a weird situation: I send a pdf to the user using this line in my controller: format.pdf { render :file => pdf_file_path } This has been working fine. But, on one specific file (meaning specific file content) I get this error, which makes it look like Ruby via Rails is trying to interpret the content of the file as code. Because other files are downloading fine, and from the error message I conclude that Ruby is in fact trying to interpret the file content: exception.message: \"compile error\\n\\\n /media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char `\\\\225' in expression\\n\\\n /media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char `\\\\263' in expression\\n\\\n /media/lqidatastore/production/temp/297_standard_view.pdf:736: syntax error, unexpected tIDENTIFIER, expecting kEND\\n\\\n ; Y`\\ao0\\x01\\a\\x83\\x16\\x97a\\x1E\\\\\\xA3\\x98\\e\\xB58\\x8CsV\\xB5\\xE0\\xBC9`\\x95\\xB3p\\x84\\xD2\\xEA!\\x84+\\xD3\\xE2\\xF7H\\xD3j\\xB0\\x8Ch\\vc\\x1D[\\x0F\\xF4\\x19t\\n The actual error is longer but you get the point. There is no line 736 in my controller, but there is in the pdf file: Line 736: ∏ Õ3"ögD4œàhû —< ¢yFDÛåàÊ Õ3"öÁB¥¿àhÅ — #¢ FD \à -0"Z`D¥¿àhÅ —"#¢EFDãåà -r!ZdD¥»àhë —"#¢E&DÉö —Z€LÅ÷ŸÊ ¥÷6S†µ∂y ç —Z€lÅ∆áh≠m∂@„B4≈àhä — #¢)FDS\චM1"öbD4≈àhä —4#¢iFD”åචMs! cÕ�0÷�cÕ�0÷�WÕ�0÷�cÕ�0÷�cÕ�p’�cÕ�0÷�cÕ�0÷�WÕ�0÷�cÕ�0÷�cÕ�p’�cÕ�0÷�cÕ�0÷�WÕ�0÷�cÕ�0÷�cÕ�†öÅm æpøp‡ã€›ÂµÜÊ· ∑ *’˛˛Y˜Ì6ı:ı@ß flæØ~N¡Æ~©n?Óîn~Ÿµ\u-Í°E=ÔZ`© –Q µÑ∂%<4Ë m√´€›õ# 2⁄~Áírùa3 ÓÏ®z W˙˛ Ÿ kÄ`tçG É ¿£˚í¬É&F« òzÍÅz5µ¨qÔ:/ÌRwQ¿‡”‡ñ∫ ¨a¨ÍÎ∂!NáatÃÃpí\ÏP´Ô/vò⁄ôπÿhÍóìH4 ç&Iwõyo —ıf˝d Ò 2/ ‹{t°ë;¯z†kàMœ‹t¬‚HËÇ≈?jÙ±i˝ u ı˜«—çé1Ë¥∫ûûÖÓ2'DÏç ‰±E A-3 „P |lkçu<;WÙÁ -$Ïbî}Ñ Ê≈4bAx∫M ö a|ö}#LBdÉ◊ZOßüCÃÜ∏ yT[t IÃw§5 7Éñ'”)ã©e/Ó.ÕY<â◊05:Ô ®ZCÜË¢ Ño¯2Õ�' So the million dollar question is what could make Rails decide to interpret the content of a file which we are asking for it to pass down to the user? And better yet, is there a way I can tell Rails "hey, this is a file, lay off"? David -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Dec-10 10:09 UTC
Re: Rails/ruby seems to be interpreting the content in "render :file" request
On 10 December 2010 04:40, David Kahn <dk@structuralartistry.com> wrote:> Got a weird situation: > > I send a pdf to the user using this line in my controller: > format.pdf { render :file => pdf_file_path } > > This has been working fine. But, on one specific file (meaning specific file > content) I get this error, which makes it look like Ruby via Rails is trying > to interpret the content of the file as code. Because other files are > downloading fine, and from the error message I conclude that Ruby is in fact > trying to interpret the file content: > > exception.message: \"compile error\\n\\\n > /media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char > `\\\\225' in expression\\n\\\n > /media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char > `\\\\263' in expression\\n\\\nAre you sure it is a rails error? Does it have a conventional ruby stack trace dump? If so can you post it? What do you see in the rails log? Colin> /media/lqidatastore/production/temp/297_standard_view.pdf:736: syntax error, > unexpected tIDENTIFIER, expecting kEND\\n\\\n ; > Y`\\ao0\\x01\\a\\x83\\x16\\x97a\\x1E\\\\\\xA3\\x98\\e\\xB58\\x8CsV\\xB5\\xE0\\xBC9`\\x95\\xB3p\\x84\\xD2\\xEA!\\x84+\\xD3\\xE2\\xF7H\\xD3j\\xB0\\x8Ch\\vc\\x1D[\\x0F\\xF4\\x19t\\n > > The actual error is longer but you get the point. There is no line 736 in my > controller, but there is in the pdf file: > > Line 736: > ∏ Õ3"ögD4œàhû —< ¢yFDÛåàÊ Õ3"öÁB¥¿àhÅ — #¢ FD \à -0"Z`D¥¿àhÅ —"#¢EFDãåà > -r!ZdD¥»àhë —"#¢E&DÉö —Z€LÅ÷ŸÊ ¥÷6S†µ∂y ç —Z€lÅ∆áh≠m∂@„B4≈àhä — #¢)FDS\ච> M1"öbD4≈àhä —4#¢iFD”åචMs! cÕ�0÷ �cÕ�0÷ �WÕ�0÷ �cÕ�0÷ �cÕ�p’ �cÕ�0÷ �cÕ�0÷ > �WÕ�0÷ �cÕ�0÷ �cÕ�p’ �cÕ�0÷ �cÕ�0÷ �WÕ�0÷ �cÕ�0÷ �cÕ�†öÅm æpøp‡ã€›ÂµÜÊ· ∑ > *’˛˛Y˜Ì6ı:ı@ß flæØ~N¡Æ~©n?Óîn~Ÿµ\u-Í°E=ÔZ`© –Q µÑ∂%<4Ë m√´€›õ# 2⁄~Áírùa3 ÓÏ®z > W˙˛ Ÿ kÄ`tçG É ¿£˚í¬É&F« òzÍÅz5µ¨qÔ:/ÌRwQ¿‡”‡ñ∫ > ¨a¨ÍÎ∂!NáatÃÃpí\ÏP´Ô/vò⁄ôπÿhÍóìH4 ç&Iwõyo —ıf˝d Ò 2/ ‹{t°ë;¯z†kàMœ > ‹t¬‚HËÇ≈?jÙ±i˝ u ı˜«—çé1Ë¥∫ûûÖÓ2'DÏç ‰±E A-3 „P |lkçu<;WÙÁ -$Ïbî}Ñ Ê≈4bAx∫M > ö a|ö}#LBdÉ◊ZOßüCÃÜ∏ yT[t IÃw§5 7Éñ'”)ã©e/Ó.ÕY<â◊05:Ô ®ZCÜË¢ Ño¯2Õ�' > > > So the million dollar question is what could make Rails decide to interpret > the content of a file which we are asking for it to pass down to the user? > And better yet, is there a way I can tell Rails "hey, this is a file, lay > off"? > > David > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Dec-10 12:29 UTC
Re: Rails/ruby seems to be interpreting the content in "render :file" request
On Dec 10, 4:40 am, David Kahn <d...@structuralartistry.com> wrote:> Got a weird situation: > > I send a pdf to the user using this line in my controller: > format.pdf { render :file => pdf_file_path } > > This has been working fine. But, on one specific file (meaning specific file > content) I get this error, which makes it look like Ruby via Rails is trying > to interpret the content of the file as code. Because other files are > downloading fine, and from the error message I conclude that Ruby is in fact > trying to interpret the file content: > > exception.message: \"compile error\\n\\\n > /media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char > `\\\\225' in expression\\n\\\n > /media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char > `\\\\263' in expression\\n\\\n > /media/lqidatastore/production/temp/297_standard_view.pdf:736: syntax error, > unexpected tIDENTIFIER, expecting kEND\\n\\\n ; > Y`\\ao0\\x01\\a\\x83\\x16\\x97a\\x1E\\\\\\xA3\\x98\\e\\xB58\\x8CsV\\xB5\\xE 0\\xBC9`\\x95\\xB3p\\x84\\xD2\\xEA!\\x84+\\xD3\\xE2\\xF7H\\xD3j\\xB0\\x8Ch\ \vc\\x1D[\\x0F\\xF4\\x19t\\n > > The actual error is longer but you get the point. There is no line 736 in my > controller, but there is in the pdf file: > > Line 736: > ∏ Õ3"ögD4œàhû —< ¢yFDÛåàÊ Õ3"öÁB¥¿àhÅ — #¢ FD \à -0"Z`D¥¿àhÅ —"#¢EFDãåà -r!ZdD¥»àhë —"#¢E&DÉö —Z€LÅ÷ŸÊ > ¥÷6S†µ∂y ç —Z€lÅ∆áh≠m∂@„B4≈àhä — #¢)FDS\චM1"öbD4≈àhä —4#¢iFD”åචMs! cÕ 0÷ cÕ 0÷ WÕ 0÷ cÕ 0÷ cÕ p’ cÕ 0÷ cÕ 0÷ WÕ 0÷ cÕ 0÷ cÕ p’ cÕ 0÷ cÕ 0÷ WÕ 0÷ cÕ 0÷ cÕ †öÅm æpøp‡ã€›ÂµÜÊ· ∑ *’˛˛Y˜Ì6ı:ı@ß flæØ~N¡Æ~©n?Óîn~Ÿµ\u-Í°E=ÔZ`© –Q µÑ∂%<4Ë m√´€›õ# 2⁄~Áírùa3 ÓÏ®z W˙˛ Ÿ kÄ`tçG É ¿£˚í¬É&F« òzÍÅz5µ¨qÔ:/ÌRwQ¿‡”‡ñ∫ ¨a¨ÍÎ∂!NáatÃÃpí\ÏP´Ô/vò⁄ôπÿhÍóìH4 ç&Iwõyo —ıf˝d > Ò 2/ ‹{t°ë;¯z†kàMœ‹t¬‚HËÇ≈?jÙ±i˝ u ı˜«—çé1Ë¥∫ûûÖÓ2'DÏç ‰±E A-3 „P |lkçu<;WÙÁ -$Ïbî}Ñ Ê≈4bAx∫M ö a|ö}#LBdÉ◊ZOßüCÃÜ∏ yT[t IÃw§5 7Éñ'”)ã©e/Ó.ÕY<â◊05:Ô ®ZCÜË¢ Ño¯2Õ ' > > So the million dollar question is what could make Rails decide to interpret > the content of a file which we are asking for it to pass down to the user? > And better yet, is there a way I can tell Rails "hey, this is a file, lay > off"?If you actually just want to send a file, use send_file. render :file means 'here is a template, please execute it". Fred> > David-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2010-Dec-10 15:08 UTC
Re: Re: Rails/ruby seems to be interpreting the content in "render :file" request
On Fri, Dec 10, 2010 at 6:29 AM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Dec 10, 4:40 am, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote: > > Got a weird situation: > > > > I send a pdf to the user using this line in my controller: > > format.pdf { render :file => pdf_file_path } > > > > This has been working fine. But, on one specific file (meaning specific > file > > content) I get this error, which makes it look like Ruby via Rails is > trying > > to interpret the content of the file as code. Because other files are > > downloading fine, and from the error message I conclude that Ruby is in > fact > > trying to interpret the file content: > > > > exception.message: \"compile error\\n\\\n > > /media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid > char > > `\\\\225'' in expression\\n\\\n > > /media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid > char > > `\\\\263'' in expression\\n\\\n > > /media/lqidatastore/production/temp/297_standard_view.pdf:736: syntax > error, > > unexpected tIDENTIFIER, expecting kEND\\n\\\n ; > > > Y`\\ao0\\x01\\a\\x83\\x16\\x97a\\x1E\\\\\\xA3\\x98\\e\\xB58\\x8CsV\\xB5\\xE > 0\\xBC9`\\x95\\xB3p\\x84\\xD2\\xEA!\\x84+\\xD3\\xE2\\xF7H\\xD3j\\xB0\\x8Ch\ > \vc\\x1D[\\x0F\\xF4\\x19t\\n > > > > The actual error is longer but you get the point. There is no line 736 in > my > > controller, but there is in the pdf file: > > > > Line 736: > > ∏ Õ3"ögD4œàhû —< ¢yFDÛåàÊ Õ3"öÁB¥¿àhÅ — #¢ FD \à -0"Z`D¥¿àhÅ > —"#¢EFDãåà -r!ZdD¥»àhë —"#¢E&DÉö —Z€LÅ÷ŸÊ > > ¥÷6S†µ∂y ç —Z€lÅ∆áh≠m∂@„B4≈àhä — #¢)FDS\චM1"öbD4≈àhä —4#¢iFD”åචMs! > cÕ 0÷ cÕ 0÷ WÕ 0÷ cÕ 0÷ cÕ p’ cÕ 0÷ cÕ 0÷ WÕ 0÷ cÕ 0÷ cÕ p’ cÕ 0÷ > cÕ 0÷ WÕ 0÷ cÕ 0÷ cÕ †öÅm æpøp‡ã€›ÂµÜÊ· ∑ *’˛˛Y˜Ì6ı:ı@ß > flæØ~N¡Æ~©n?Óîn~Ÿµ\u-Í°E=ÔZ`© –Q µÑ∂%<4Ë m√´€›õ# 2⁄~Áírùa3 ÓÏ®z W˙˛ Ÿ kÄ`tçG > É ¿£˚í¬É&F« òzÍÅz5µ¨qÔ:/ÌRwQ¿‡”‡ñ∫ ¨a¨ÍÎ∂!NáatÃÃpí\ÏP´Ô/vò⁄ôπÿhÍóìH4 > ç&Iwõyo —ıf˝d > > Ò 2/ ‹{t°ë;¯z†kàMœ‹t¬‚HËÇ≈?jÙ±i˝ u ı˜«—çé1Ë¥∫ûûÖÓ2''DÏç ‰±E A-3 „P > |lkçu<;WÙÁ -$Ïbî}Ñ Ê≈4bAx∫M ö a|ö}#LBdÉ◊ZOßüCÃÜ∏ yT[t IÃw§5 > 7Éñ''”)ã©e/Ó.ÕY<â◊05:Ô ®ZCÜË¢ Ño¯2Õ '' > > > > So the million dollar question is what could make Rails decide to > interpret > > the content of a file which we are asking for it to pass down to the > user? > > And better yet, is there a way I can tell Rails "hey, this is a file, lay > > off"? > > If you actually just want to send a file, use send_file. render :file > means ''here is a template, please execute it". >Thanks, right on. One question though: if I call "render :text = > response" does this also get interpreted? If I am returning xml (which has an embeded pdf doc), am I better of using send_data or render :text?> > Fred > > > > David > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Dec-10 15:19 UTC
Re: Rails/ruby seems to be interpreting the content in "render :file" request
On Dec 10, 3:08 pm, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote:> On Fri, Dec 10, 2010 at 6:29 AM, Frederick Cheung < > > Thanks, right on. One question though: if I call "render :text = > response" > does this also get interpreted? If I am returning xml (which has an embeded > pdf doc), am I better of using send_data or render :text? >render :text will just dump what you pass straight into the response ( it''s what send_data uses internally). send_data is mostly a convenience that sets headers like Content- disposition for you. If you have an actual file then send_file can be more efficient if you use the x-send-file or stream options since those don''t entail loading the whole file into your rails process. Fred> > > > > > Fred > > > > David > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2010-Dec-10 15:38 UTC
Re: Re: Rails/ruby seems to be interpreting the content in "render :file" request
On Fri, Dec 10, 2010 at 9:19 AM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 10, 3:08 pm, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote: > > On Fri, Dec 10, 2010 at 6:29 AM, Frederick Cheung < > > > > Thanks, right on. One question though: if I call "render :text = > > response" > > does this also get interpreted? If I am returning xml (which has an > embeded > > pdf doc), am I better of using send_data or render :text? > > > > render :text will just dump what you pass straight into the response > ( it''s what send_data uses internally). > send_data is mostly a convenience that sets headers like Content- > disposition for you. If you have an actual file then send_file can be > more efficient if you use the x-send-file or stream options since > those don''t entail loading the whole file into your rails process. >Perfect, thanks... looks like problem solved!> > Fred > > > > > > > > > > > > Fred > > > > > > David > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Ruby on Rails: Talk" group. > > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.