Skip to content

Commit be49fc8

Browse files
committed
Fix bug where method= filter would suggest invalid method values
If you have unparseable traffic (e.g. MQTT) and you try to filter by method, it will suggest the invalid MQTT method as an option, and if you try it then everything will crash. We now filter for only know valid methods.
1 parent 71656ed commit be49fc8

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/model/filters/search-filters.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as _ from 'lodash';
22

3-
import { ViewableEvent } from '../../types';
3+
import { HttpExchangeView, ViewableEvent } from '../../types';
44
import { joinAnd } from '../../util/text';
55
import { stringToBuffer } from '../../util/buffer';
66

7-
import { getStatusDocs } from '../http/http-docs';
7+
import { getStatusDocs, METHOD_NAMES } from '../http/http-docs';
88
import { getReadableSize } from '../../util/buffer';
99
import { EventCategories } from '../events/categorization';
1010
import { WebSocketStream } from '../websockets/websocket-stream';
@@ -461,9 +461,15 @@ class MethodFilter extends Filter {
461461
allowedChars: ALPHABETICAL,
462462
suggestionGenerator: (_v, _i, events: ViewableEvent[]) =>
463463
_(events)
464-
.map(e => e.isHttp() && e.request.method)
464+
.filter(e =>
465+
e.isHttp() &&
466+
!!e.request.method &&
467+
METHOD_NAMES.includes(e.request.method.toUpperCase())
468+
)
469+
.map((e) =>
470+
(e as HttpExchangeView).request.method.toUpperCase()
471+
)
465472
.uniq()
466-
.filter(Boolean)
467473
.valueOf() as string[]
468474
})
469475
] as const;

src/model/http/http-docs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,9 @@ export function getWebSocketCloseCodeDocs(closeCode: string | number | undefined
10361036
return WEBSOCKET_CLOSE_CODES[closeCode.toString()];
10371037
}
10381038

1039+
export const METHOD_NAMES = (Object.values(METHODS) as MdnDocsData[])
1040+
.map(({ name }) => name.toUpperCase());
1041+
10391042
export function getMethodDocs(methodName: string) {
10401043
return getDocs(METHODS, methodName.toLowerCase());
10411044
}

0 commit comments

Comments
 (0)