CampaignSegmentTest and commas


Building from the latest source and calling MCApi.CampaignSegmentTest with a segment condition that looks like:
new Campaign.SegmentCondition("interests-1", "one", string.Join(",", new string[] { "Beer\, Wine and Spirits", "Pretzels" }))
ends up double-escaping the comma, so you get a form value like (URL unescaped for clarity):
options[conditions][0][value]=Beer\, Wine and Spirits\, Pretzels
And results in an error like "Beer\, Wine and Spirits, Pretzels" is not a valid Interest Group for the list xxx
If you don't pre-escape the comma you'd get "Beer\, Wine and Spirits\, Pretzels" which is also invalid. The only way I could figure out to get around it was to edit the code and remove the part from InputHelper.joinSeq where it does a blanket replace on commas.
Maybe I'm doing something wrong?


denisk1981 wrote Jun 27, 2011 at 10:31 AM

1) Fixed :)

2) There are several options now to build segment_opts. Think about more complex scenario when groups names include commas and backslashes,
like: "\X1\", "X2,X2", "X3\,X3", "X4\,X4".

In general, u don't have to escape commas with "\". It happens automatically. U can override this by postpending commas with another backslash - ",\" (it will be removed automatically).

The next expressions produce the same result "\X1\ , X2\,X2, X3\,X3, X4\\,X4":

Single condition:

a) var cnd = new Campaign.SegmentCondition("interests-1", "one", @"\X1\ ,\ X2,X2,\ X3\,X3,\ X4\,X4");

b) var cnd = new Campaign.SegmentCondition("interests-1", "one", new string [] { @"\X1\", @"X2,X2", @"X3\,X3", @"X4\,X4" });

Segment Options parameter:

a) var sopt = Campaign.SegmentOptions.Parse(Campaign.Match.AND,
                @"interests-1 => one => \X1\ , X2\,X2, X3\\,X3, X4\\\,X4");
b) var sopt = Campaign.SegmentOptions.Parse(Campaign.Match.AND,
                new string[] { @"interests-1 => one => \X1\ , X2\,X2, X3\\,X3, X4\\\,X4" });

P.S. Use @ :)

wrote Feb 21, 2013 at 10:44 PM

wrote May 16, 2013 at 10:23 AM

wrote May 16, 2013 at 10:23 AM

wrote Jun 14, 2013 at 7:23 AM