File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -214,7 +214,12 @@ func (p *parser) addresses() error {
214
214
value := p .Val ()
215
215
token := p .Token ()
216
216
217
- // special case: import directive replaces tokens during parse-time
217
+ // Reject request matchers if trying to define them globally
218
+ if strings .HasPrefix (value , "@" ) {
219
+ return p .Errf ("request matchers may not be defined globally, they must be in a site block; found %s" , value )
220
+ }
221
+
222
+ // Special case: import directive replaces tokens during parse-time
218
223
if value == "import" && p .isNewLine () {
219
224
err := p .doImport (0 )
220
225
if err != nil {
Original file line number Diff line number Diff line change @@ -857,6 +857,29 @@ func TestSnippetAcrossMultipleFiles(t *testing.T) {
857
857
}
858
858
}
859
859
860
+ func TestRejectsGlobalMatcher (t * testing.T ) {
861
+ p := testParser (`
862
+ @rejected path /foo
863
+
864
+ (common) {
865
+ gzip foo
866
+ errors stderr
867
+ }
868
+
869
+ http://example.com {
870
+ import common
871
+ }
872
+ ` )
873
+ _ , err := p .parseAll ()
874
+ if err == nil {
875
+ t .Fatal ("Expected an error, but got nil" )
876
+ }
877
+ expected := "request matchers may not be defined globally, they must be in a site block; found @rejected, at Testfile:2"
878
+ if err .Error () != expected {
879
+ t .Errorf ("Expected error to be '%s' but got '%v'" , expected , err )
880
+ }
881
+ }
882
+
860
883
func testParser (input string ) parser {
861
884
return parser {Dispenser : NewTestDispenser (input )}
862
885
}
You can’t perform that action at this time.
0 commit comments