I ran into an issue where I entered two view arguments on separate lines, but I was getting a blank PDF because the argument string was not converted to the array properly. I traced the issue to the fact that on a Mac [Not sure if this is the case elsewhere] a new line is entered w/ a carriage return character and a new line character, thus, the explode string would need to be "\r\n".
I know that would break it for systems w/out the extra character in a new line, so I cam up w/ the attached patch to strip out carriage returns [and tabs and spaces, just in case], before setting the argument.
The attached patch works on Mac, haven't tried it on PC. If someone else could that'd be great, not sure when I'll be able to.
Comment | File | Size | Author |
---|---|---|---|
#15 | Rules-Args-Explode-2289779-15.patch | 1.57 KB | vegansupreme |
#9 | Rules-Args-Explode-2289779-9.patch | 492 bytes | vegansupreme |
Rules-Args-Explode.patch | 585 bytes | stiknoltz |
Comments
Comment #1
vegansupreme CreditAttribution: vegansupreme commentedWorks for me. I haven't tried it on a PC though, only Mac.
Comment #2
killua99 CreditAttribution: killua99 commentedActually this code need to have PHP_EOL .. I'll try to fix it.
@whoisinkus maybe you can try it, use PHP_EOL instead the " \r\n" etc ...
Comment #3
killua99 CreditAttribution: killua99 commentedComment #4
vegansupreme CreditAttribution: vegansupreme commented@Killua99 I tried replacing the "\r\n…" with PHP_EOL, but it didn't work. I could replace the
explode("\n", $arguments)
withexplode(PHP_EOL, $arguments)
but it still seems to leave the extra \r.Here's a patch that uses PHP_EOL, but I don't know if it's functionally any different from whoisinkus' original.
Comment #5
killua99 CreditAttribution: killua99 commented$args[$k] = trim($v, PHP_EOL . "\t"); doesn't work?
Where did you tried to replace it?
Comment #6
vegansupreme CreditAttribution: vegansupreme commentedOh I had tried
$args[$k] = trim($v, PHP_EOL);
hopefully I can test
$args[$k] = trim($v, PHP_EOL . "\t");
on Monday.Comment #7
vegansupreme CreditAttribution: vegansupreme commented$args[$k] = trim($v, PHP_EOL . "\t");
doesn't work. I don't' know if it's because I'm using MAMP for dev environment…It seems odd to have arguments separated by newlines in the first place. Could arguments be separated by "/" instead, as they are in the URL? Or would that cause some other problems? Maybe someone wants a "/" as part of their argument—it would have to be escaped. That said, whoisinkus' patch does solve the problem on Mac. I haven't been able to test on other platforms.
Comment #8
killua99 CreditAttribution: killua99 commentedI just saw something
When you explore with PHP_EOL is remove the "\n" or "\r\n" from each array. So what exactly doesn't work with the $args[$k] = trim($v, PHP_EOL . "\t"); ? maybe you should do $args[$k] = trim($v, " \t"); ( I see a space in " and \).
Tell me if I'm wrong.
Comment #9
vegansupreme CreditAttribution: vegansupreme commentedtrim($v, PHP_EOL . "\t") still leaves a carriage return in the argument, so does trim($v, " \t") and trim($v, PHP_EOL." \t"). I've tried every permutation I could think of.
The only options that worked were
trim($v, PHP_EOL."\r\n\t" )
andtrim($v, "\r\n\t" )
Just found a different way to do it that seems to work. Using preg_split() instead of explode()
http://stackoverflow.com/questions/1483497/how-to-put-string-in-array-sp...
This patch works on Mac, but haven't tested on PC. If someone else could test on PC that would be great. I'm not sure when I'll be able to.
Comment #10
vegansupreme CreditAttribution: vegansupreme commentedComment #11
killua99 CreditAttribution: killua99 commentedWhy don't use \R then ? looks a better solution for me use preg_split weird we can't use PHP_EOL. Did you try it? "/" . PHP_EOL . "/". The reason I'll like to use PHP_EOL is for the support for multiples S.O and we don't have to write one by one, just that.
Comment #12
vegansupreme CreditAttribution: vegansupreme commentedHere's what I've tried:
$args[$k] = trim($v,"/".PHP_EOL."/"); NO
$args[$k] = trim($v, PHP_EOL); NO
$args[$k] = trim($v, PHP_EOL."\R"); NO
$args[$k] = trim($v, PHP_EOL." \R"); NO
$args[$k] = trim($v,'/'.PHP_EOL.'/'); NO
$args = explode(PHP_EOL, $arguments); NO
Nothing with EOL works. It would be a great if it did, but I haven't been able to get it working. It seems to be interpreting PHP_EOL as /n only. /n would probably work just fine when outputting a string, that is, it would be rendered as a newline just fine.
When I export the rule it says
"arguments" : "5\r\n25",
I did some research:
When entering text into the browser, it uses CR+LF, I suspect this is true on Mac and PC. But PHP is running on Linux (or Mac OS kernel) which uses LF only.
Therefore PHP_EOL can't work in this situation because it's only looking for LF—leaving behind the CR, and causing the argument not to validate.
Comment #13
vegansupreme CreditAttribution: vegansupreme commentedDid a quick test on a PC with IE. It also uses \r\n.
Comment #14
vegansupreme CreditAttribution: vegansupreme commentedHow about we take an entirely different approach? It seems strange to use return separated arguments in the first place.
I took a look at how Views Field View handles contextual filters. They use commas or forward slash to separate values.
from the UI:
Comment #15
vegansupreme CreditAttribution: vegansupreme commentedreroll patch from #14. If no objections I'll commit this soon.
Comment #16
vegansupreme CreditAttribution: vegansupreme commentedActually I don't like this solution, because it wouldn't work well with multi-value arguments; a comma separated list of NIDs for example. I'll commit patch #9 if there are no objections.
Comment #18
vegansupreme CreditAttribution: vegansupreme commentedCommitted to dev.