Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
WebMock and url escaping/encoding
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rhett Sutphin  
View profile  
 More options Feb 27 2012, 12:23 am
From: Rhett Sutphin <rhett.sutp...@gmail.com>
Date: Sun, 26 Feb 2012 23:23:00 -0600
Subject: WebMock and url escaping/encoding
Hi,

I've just started using WebMock. Among other things, I like the way it lets me verify the body of a request using a block, rather than just a string or regex.

I do have one problem with it, though: the fact that it considers escaped and unescaped URIs to be equivalent. The API I'm interacting with only works if I issue requests that are escaped. E.g.,

conn.get('studies/A Test/template')

will not work, while

conn.get('studies/A%20Test/template')

will. (I'm using Faraday with the Net::HTTP adapter for the client.)

Since WebMock considers "http://example.net/studies/A Test/template" and "http://example.net/studies/A%20Test/template" to be the same request, I can't test that my client code is properly escaping its request URIs. Is there a way to change WebMock's behavior so it doesn't consider these URIs to be the same?

I've looked through the code and the docs and not seen anything, but I thought I'd ask in case anyone more experienced with the library has a suggestion.

Thanks,
Rhett


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bartosz Blimke  
View profile  
 More options Feb 27 2012, 6:54 am
From: Bartosz Blimke <bartosz.bli...@gmail.com>
Date: Mon, 27 Feb 2012 12:54:38 +0100
Local: Mon, Feb 27 2012 6:54 am
Subject: Re: WebMock and url escaping/encoding

There is no way to do that without changing WebMock. Maybe there should be
some configurable strict mode in WebMock.

WebMock uses addressable for comparing uris and Addressable treats uris
that way.

u1 = Addressable::URI.parse("
http://www.example.com/studies/A%20Test/template")
u2 = Addressable::URI.parse("http://www.example.com/studies/ATest/template")
u1 === u2   #=> true

It very much depends on the http client library you use. Some libs will
consider these two urls as the same.

Bartosz

2012/2/27 Rhett Sutphin <rhett.sutp...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rhett Sutphin  
View profile  
 More options Feb 27 2012, 4:27 pm
From: Rhett Sutphin <rhett.sutp...@gmail.com>
Date: Mon, 27 Feb 2012 15:27:49 -0600
Local: Mon, Feb 27 2012 4:27 pm
Subject: Re: WebMock and url escaping/encoding
Hi Bartosz,

On Feb 27, 2012, at 5:54 AM, Bartosz Blimke wrote:

> There is no way to do that without changing WebMock. Maybe there should be
> some configurable strict mode in WebMock.

> WebMock uses addressable for comparing uris and Addressable treats uris that way.

> u1 = Addressable::URI.parse("http://www.example.com/studies/A%20Test/template")
> u2 = Addressable::URI.parse("http://www.example.com/studies/A Test/template")
> u1 === u2   #=> true

> It very much depends on the http client library you use. Some libs will consider these two urls as the same.

Thanks for your reply. In my case, the problem not the client so much as the service -- whatever HTTP client (or even curl) I use, if it receives a URI with a path component with an unescaped value in it, it won't handle it properly. I'd like to be able to use a testing library to verify that the URIs my code is using fit this constraint. After I sent my last e-mail, it occurred to me that I might be able to do this:

WebMock.should have_requested(:get, "http://www.example.com/studies/A%20Test/template") do |request|
  request.uri.to_s == request.uri.normalize.to_s
end

However, this doesn't fail when the tested code does not escape the URI. Reviewing the code, it seems like WebMock normalizes URIs as soon as it encounters them, both expected and actual, so it would indeed be a big change to be able to test proper escaping.

Thanks again for your time,
Rhett


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bartosz Blimke  
View profile  
 More options Feb 28 2012, 3:50 am
From: Bartosz Blimke <bartosz.bli...@gmail.com>
Date: Tue, 28 Feb 2012 09:50:30 +0100
Local: Tues, Feb 28 2012 3:50 am
Subject: Re: WebMock and url escaping/encoding

It would have to be configuration in webmock 1.x. Changing this behaviour
in 1.x series would break compatibility.

I'll think what's the best option for webmock 2.0

Bartosz

2012/2/27 Rhett Sutphin <rhett.sutp...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »