Skip to content

Commit f9b218c

Browse files
authored
Merge pull request #411 from REditorSupport/fix_string_detection
fix raw string detection
2 parents 3faeee2 + 06d9ac4 commit f9b218c

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/fsm.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ void fsm_feed(fsm_state* state, const char c) {
3535
return;
3636
} else {
3737
state->raw_parse_state = 0;
38-
state->double_quoted = 0;
39-
state->single_quoted = 0;
4038
}
4139
} else if (state->raw_parse_state == 2) {
4240
if (c == '(' || c == '[' || c == '{') {
@@ -104,9 +102,7 @@ void fsm_feed(fsm_state* state, const char c) {
104102
return;
105103
}
106104

107-
if (c == 'R' || c == 'r') {
108-
state->raw_parse_state = 1;
109-
} else if (c == '\\') {
105+
if (c == '\\') {
110106
state->escaped = 1;
111107
} else if (state->single_quoted || state->double_quoted || state->backticked) {
112108
// inside string or backticks
@@ -116,5 +112,7 @@ void fsm_feed(fsm_state* state, const char c) {
116112
state->single_quoted = 1;
117113
} else if (c == '"') {
118114
state->double_quoted = 1;
115+
} else if (c == 'R' || c == 'r') {
116+
state->raw_parse_state = 1;
119117
}
120118
}

tests/testthat/test-search.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ test_that("enclosed_by_quotes works as expected", {
1717
expect_true(enclosed("R\"-(a)\"hello_world", 9))
1818
expect_true(enclosed("'\\'hello_world", 4))
1919
expect_false(enclosed("'a'hello_world", 4))
20+
#410
21+
expect_true(enclosed("fun('free', )", 8))
22+
expect_false(enclosed("fun('free', )", 9))
2023
})
2124

2225

0 commit comments

Comments
 (0)