WebObjects 5.3.1 WORedirect Bug

I’m encountering a problem with WebObjects 5.3.1 and WORedirect. It looks like WORedirect is encoding the ampersand (&) url parameter separator, but WO is not respecting this when it extracts the values again.

You can see this behavior with this code:

In your WOComponent:

public WORedirect createDA(){
	NSMutableDictionary dict = new NSMutableDictionary();
	dict.takeValueForKey("Zero", "valueZero");
	dict.takeValueForKey(String.valueOf(1), "valueOne");
	dict.takeValueForKey("Two", "valueTwo");
	NSLog.out.appendln("Before: " + dict);
	String url = context().directActionURLForActionNamed( 
					"default", dict ); 
	WORedirect redirect = new WORedirect(context());
	NSLog.out.appendln("URL: " + url);
	redirect.setUrl(url);
	return redirect;
}

In your DirectAction Class:

public WOActionResults defaultAction() {
    NSLog.out.appendln("After: " + request().formValues());
    return pageWithName("Main");
}

You’ll see something like this in the Console:

Pre: {valueZero = "Zero"; valueTwo = "Two"; valueOne = "1"; }

URL: /cgi-bin/WebObjects/NewWOTest.woa/wa/default?valueZero=Zero&valueTwo=Two&valueOne=1

After: {valueZero = ("Zero"); amp;valueTwo = ("Two"); amp;valueOne = ("1");}

Because WO doesn’t respect the encoding when it extracts the URL values you end up with munged dictionary keys. This pretty much breaks using WORedirect to call a DirectAction. I can’t see an easy workaround.

I’m still trying to figure out if this is a problem with my setup or whether it is a bug. If it’s a bug, I’ll be very disappointed. I use WORedirect extensively in a number of apps and this’ll mean I’ll have to revert to WO 5.2.4 (again).

Update: I filed a bug on this.

Update: OK this is really ugly. But… I need this to work, so as a hack I’m adding a line to my WORedirects so they look like this:

public WORedirect createDA(){
	NSMutableDictionary dict = new NSMutableDictionary();
	dict.takeValueForKey("Zero", "valueZero");
	dict.takeValueForKey(String.valueOf(1), "valueOne");
	dict.takeValueForKey("Two", "valueTwo");
	NSLog.out.appendln("Pre: " + dict);
	String url = context().directActionURLForActionNamed( 
					"default", dict ); 
	url = url.replaceAll("&", "&");
	WORedirect redirect = new WORedirect(context());
	NSLog.out.appendln("URL: " + url);
	redirect.setUrl(url);
	return redirect;
}

7 thoughts on “WebObjects 5.3.1 WORedirect Bug

  1. Same thing happened in my app with just generating a direct action URL to put in a javascript redirect … I don’t think it’s your code.

  2. I think we should be clear that the bug is not with WORedirect but rather with WOContext. (or something that WOContext calls)

    During the generation of the URL in the call to directActionURLForActionNamed(…) the ampersands (&) are being encoded when the parameters from the dictionary are appended to the URL.

  3. I don’t know about that Galen,

    Yes the context().directActionURLForActionNamed(…) method is encoding the ampersands. But that would be the correct behaviour if you wanted to embed the URL in your page (ie: use it with a WODynamicElement).

    If you click on a URL containing encoded ampersands with a browser, it will decode them before making the request.

    I think WORedirect is kind of acting like a browser in this instance and should be decoding the ampersands as well.

    Obviously, I didn’t write the code. So I’ll let Apple decide what the correct behavior should be or where the fix should lie.

  4. I don’t think so, I think that WORedirect is just sending the request as is, and it’s confusing WORequest when you ask for formValues().

  5. Same problem with a WOHyperlink with href binding and parameters (bindings starting with a ?): & instead of & in the generate url.

  6. for WOHyperlink, I found the culprit: in com.webobjects.appserver._private.WOURLEncoder.encodeAsCGIFormValues(…) “&” has been replaced with “&” in WO 5.3.1.

Comments are closed.