1

Resolved

Bug in Workflow : Webrequest

description

Hi There

I am using workflow web request and passing Key value pairs to an API.
The following method in WebRequestActivity.cs checks for "\n\r"
 private static IEnumerable<KeyValuePair<string, string>> ParseKeyValueString(string text) {
            return Regex.Split(text, "\n\r").Select(x => x.Split(new[] { '=' })).ToDictionary(x => x[0].Trim(), x => x[1].Trim());
        }
My form values only contain "\n"

When I changed the code to
 private static IEnumerable<KeyValuePair<string, string>> ParseKeyValueString(string text) {
            return Regex.Split(text, "\n").Select(x => x.Split(new[] { '=' })).ToDictionary(x => x[0].Trim(), x => x[1].Trim());
        }
My form collection parsed correctly.

This should probably check for either "\n" or "\n\r"

Thanks
Stanton

comments

AimOrchard wrote Sep 10, 2013 at 8:43 AM

actually, shouldn't it check for \n, \r\n (not \n\r) or \r?

AimOrchard wrote Sep 10, 2013 at 9:14 AM

I meant 'and' not 'or'

sebastienros wrote Sep 10, 2013 at 4:24 PM

Can you provide a pull request ?

Stanton_R wrote Sep 11, 2013 at 6:05 AM

Will send through today

Stanton_R wrote Sep 11, 2013 at 8:50 AM

Changed condition to be
  return Regex.Split(text, "\n\r|\r\n|\n|\r").Select(x => x.Split(new[] { '=' })).ToDictionary(x => x[0].Trim(), x => x[1].Trim());
Will send through pull request now

AimOrchard wrote Sep 11, 2013 at 9:20 AM

\n\r isn't a valid newline construct (right?)

Stanton_R wrote Sep 11, 2013 at 9:52 AM

Not sure that how the code was originally so I just left that in.

sebastienros wrote Sep 11, 2013 at 5:28 PM

I think this actually is the correct way to process lines:
    private static IEnumerable<KeyValuePair<string, string>> ParseKeyValueString(string text) {
        using (var reader = new StringReader(text)) {
            string line;
            while (null != (line = reader.ReadLine())) {

                line = line.Trim();

                // ignore empty lines
                if (String.IsNullOrWhiteSpace(line)) {
                    continue;
                }

                // step comments
                if (line.StartsWith("#")) {
                    continue;
                }

                var index = line.IndexOf("=", StringComparison.InvariantCulture);
                if (index != -1 && index != line.Length - 1) {
                    var name = line.Substring(0, index);
                    var value = line.Substring(index + 1);

                    yield return new KeyValuePair<string, string>(name, value);
                }
            }
        }
What do you think ? can you try it ?

sebastienros wrote Sep 11, 2013 at 9:14 PM

Fixed in changeset 13a7b7053163dad7d1043d5fb891edd6103b8501