Skip to content

Commit 68a9382

Browse files
committed
one more regex edge case, valid element nesting
1 parent 01531d4 commit 68a9382

4 files changed

Lines changed: 10 additions & 2 deletions

File tree

packages/graphiql/src/components/Tabs.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import React from 'react';
66

77
function TabCloseButton(props: { onClick: () => void }) {
88
return (
9-
<button
9+
<div
10+
role="button"
11+
aria-pressed={false}
1012
className="close"
1113
aria-label="Close Tab"
1214
title="Close Tab"

packages/graphiql/src/css/app.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ div.CodeMirror-lint-tooltip > * + * {
551551
} */
552552

553553
.graphiql-container .tab .close {
554+
display: inline-block;
554555
cursor: pointer;
555556
border: none;
556557
background: transparent;

packages/graphiql/src/utility/__tests__/fuzzyExtractOperationTitle.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ describe('fuzzyExtractionOperationTitle', () => {
2424
it('should return null for anonymous queries', () => {
2525
expect(fuzzyExtractOperationTitle('{}')).toEqual('<untitled>');
2626
});
27+
it('should not extract query names with comments', () => {
28+
expect(fuzzyExtractOperationTitle('# query My_3xampleQuery() {}')).toEqual(
29+
'<untitled>',
30+
);
31+
});
2732
});

packages/graphiql/src/utility/fuzzyExtractOperationTitle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Very simple and quick way of extracting the operation title from a document string (compared to parsing and traversing the whole AST).
33
*/
44
export function fuzzyExtractOperationTitle(str: string): string {
5-
const regex = /(query|subscription|mutation) ([a-zA-Z0-9_]+)/;
5+
const regex = /^[^#](query|subscription|mutation) ([a-zA-Z0-9_]+)/;
66
const match = regex.exec(str);
77

88
return match?.[2] ?? '<untitled>';

0 commit comments

Comments
 (0)