Skip to content

Commit 8006314

Browse files
captbaritonemeta-codesync[bot]
authored andcommitted
Fix infinite loop when extracting bare graphql token
Reviewed By: evanyeung Differential Revision: D94980372 fbshipit-source-id: db76c03d279d957df21f6ba3daaa429b9e860288
1 parent 83935ac commit 8006314

7 files changed

Lines changed: 82 additions & 2 deletions

File tree

compiler/crates/extract-graphql/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ pub fn extract(input: &str) -> Vec<JavaScriptSourceFeature> {
152152
continue 'code;
153153
}
154154
}
155+
} else {
156+
// EOF reached without finding a backtick
157+
continue 'code;
155158
}
156159
}
157160
let start = i;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
==================================== INPUT ====================================
2+
/**
3+
* Copyright (c) Meta Platforms, Inc. and affiliates.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
// A bare `graphql` token at the end of a file without a template literal
10+
// should not cause the extractor to loop infinitely.
11+
graphql
12+
==================================== OUTPUT ===================================
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
// A bare `graphql` token at the end of a file without a template literal
9+
// should not cause the extractor to loop infinitely.
10+
graphql

compiler/crates/extract-graphql/tests/extract_test.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<a6880296f247ee9d9d2e312d6c26b4a2>>
7+
* @generated SignedSource<<3c2cb388d73f2904eee16c3b407de258>>
88
*/
99

1010
mod extract;
1111

1212
use extract::transform_fixture;
1313
use fixture_tests::test_fixture;
1414

15+
#[tokio::test]
16+
async fn bare_graphql_token() {
17+
let input = include_str!("extract/fixtures/bare_graphql_token.js");
18+
let expected = include_str!("extract/fixtures/bare_graphql_token.expected");
19+
test_fixture(transform_fixture, file!(), "bare_graphql_token.js", "extract/fixtures/bare_graphql_token.expected", input, expected).await;
20+
}
21+
1522
#[tokio::test]
1623
async fn comments() {
1724
let input = include_str!("extract/fixtures/comments.js");
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
==================================== INPUT ====================================
2+
//- App.tsx
3+
graphql
4+
5+
//- relay.config.json
6+
{
7+
"language": "typescript",
8+
"schema": "./schema.graphql",
9+
"src": "./"
10+
}
11+
12+
//- schema.graphql
13+
type User {
14+
name: String
15+
}
16+
type Query {
17+
me: User
18+
}
19+
==================================== OUTPUT ===================================
20+
21+
22+
Artifact Map:
23+
Project: default
24+
Type: Mapping
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//- App.tsx
2+
graphql
3+
4+
//- relay.config.json
5+
{
6+
"language": "typescript",
7+
"schema": "./schema.graphql",
8+
"src": "./"
9+
}
10+
11+
//- schema.graphql
12+
type User {
13+
name: String
14+
}
15+
type Query {
16+
me: User
17+
}

compiler/crates/relay-compiler/tests/relay_compiler_integration_test.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<7afb51e0fa901e3bfae2f4df45a4d022>>
7+
* @generated SignedSource<<de4d2cb51732e8d59dea7363b863fc33>>
88
*/
99

1010
mod relay_compiler_integration;
1111

1212
use relay_compiler_integration::transform_fixture;
1313
use fixture_tests::test_fixture;
1414

15+
#[tokio::test]
16+
async fn bare_graphql_token_does_not_loop() {
17+
let input = include_str!("relay_compiler_integration/fixtures/bare_graphql_token_does_not_loop.input");
18+
let expected = include_str!("relay_compiler_integration/fixtures/bare_graphql_token_does_not_loop.expected");
19+
test_fixture(transform_fixture, file!(), "bare_graphql_token_does_not_loop.input", "relay_compiler_integration/fixtures/bare_graphql_token_does_not_loop.expected", input, expected).await;
20+
}
21+
1522
#[tokio::test]
1623
async fn client_extension_interface_backed_by_resolvers_in_throw_on_field_error() {
1724
let input = include_str!("relay_compiler_integration/fixtures/client_extension_interface_backed_by_resolvers_in_throw_on_field_error.input");

0 commit comments

Comments
 (0)