Skip to content

Commit 939210b

Browse files
elyscapesuyograo
authored andcommitted
Add ampersand to URIPATH
RFC1738 specifies that URL paths can legally contain ampersands: ; HTTP httpurl = "http://" hostport [ "/" hpath [ "?" search ]] hpath = hsegment *[ "/" hsegment ] hsegment = *[ uchar | ";" | ":" | "@" | "&" | "=" ] search = *[ uchar | ";" | ":" | "@" | "&" | "=" ] Accordingly, HAProxy (and potentially other applications) will not escape them in log files. Fixes #114
1 parent a273a05 commit 939210b

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

patterns/grok-patterns

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ URIPROTO [A-Za-z]+(\+[A-Za-z+]+)?
4040
URIHOST %{IPORHOST}(?::%{POSINT:port})?
4141
# uripath comes loosely from RFC1738, but mostly from what Firefox
4242
# doesn't turn into %XX
43-
URIPATH (?:/[A-Za-z0-9$.+!*'(){},~:;=@#%_\-]*)+
43+
URIPATH (?:/[A-Za-z0-9$.+!*'(){},~:;=@#%&_\-]*)+
4444
#URIPARAM \?(?:[A-Za-z0-9]+(?:=(?:[^&]*))?(?:&(?:[A-Za-z0-9]+(?:=(?:[^&]*))?)?)*)?
4545
URIPARAM \?[A-Za-z0-9$.+!*'|(){},~@#%&/=:;_?\-\[\]<>]*
4646
URIPATHPARAM %{URIPATH}(?:%{URIPARAM})?

spec/patterns/core_spec.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,62 @@
113113
end
114114
end
115115

116+
describe "URIPATH" do
117+
let(:pattern) { 'URIPATH' }
118+
119+
context "when matching valid URIs" do
120+
context "and the URI is simple" do
121+
let(:value) { '/foo' }
122+
123+
it "should match the path" do
124+
expect(grok_match(pattern,value)).to pass
125+
end
126+
end
127+
128+
context "and the URI has a trailing slash" do
129+
let(:value) { '/foo/' }
130+
131+
it "should match the path" do
132+
expect(grok_match(pattern,value)).to pass
133+
end
134+
end
135+
136+
context "and the URI has multiple levels" do
137+
let(:value) { '/foo/bar' }
138+
139+
it "should match the path" do
140+
expect(grok_match(pattern,value)).to pass
141+
end
142+
end
143+
144+
context "and the URI has fancy characters" do
145+
let(:value) { '/aA1$.+!*\'(){},~:;=@#%&|-' }
146+
147+
it "should match the path" do
148+
expect(grok_match(pattern,value)).to pass
149+
end
150+
end
151+
end
152+
153+
context "when matching invalid URIs" do
154+
context "and the URI has no leading slash" do
155+
let(:value) { 'foo' }
156+
157+
it "should not match the path" do
158+
expect(grok_match(pattern,value)).not_to pass
159+
end
160+
end
161+
162+
context "and the URI has invalid characters" do
163+
let(:value) { '/`' }
164+
165+
it "should not match the path" do
166+
expect(grok_match(pattern,value)).not_to pass
167+
end
168+
end
169+
end
170+
end
171+
116172
describe "IPV4" do
117173

118174
let(:pattern) { 'IPV4' }

0 commit comments

Comments
 (0)