Skip to content

Commit 6098a92

Browse files
committed
Forbid newline in string literal
1 parent f3a51c3 commit 6098a92

File tree

6 files changed

+51
-24
lines changed

6 files changed

+51
-24
lines changed

.github/workflows/main.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ jobs:
101101
- os: macOS-latest
102102
steps:
103103
- uses: actions/checkout@v2
104-
- name: Install Mac System dependencies
104+
- name: Install Boost on Mac
105105
if: startsWith(matrix.os,'macOS')
106106
run: |
107107
brew install boost
108-
- name: Install Linux dependencies
108+
- name: Install Boost on Linux
109109
if: startsWith(matrix.os,'ubuntu')
110110
run: |
111111
sudo apt-get install -y libboost-all-dev
@@ -121,6 +121,36 @@ jobs:
121121
run: cargo test --workspace --all-features --no-run --locked
122122
- name: Run tests
123123
run: cargo test --workspace --all-features --verbose
124+
125+
test(windows-latest):
126+
runs-on: windows-latest
127+
steps:
128+
- uses: actions/checkout@v2
129+
- name: Install Boost on Windows.
130+
uses: MarkusJx/install-boost@v2.1.0
131+
id: install-boost
132+
with:
133+
boost_version: 1.78.0
134+
platform_version: 2019
135+
- name: Install rust
136+
uses: actions-rs/toolchain@v1
137+
with:
138+
profile: minimal
139+
toolchain: stable
140+
override: true
141+
- name: Cache Dependencies
142+
uses: Swatinem/rust-cache@v1
143+
- name: Build
144+
run: cargo test --workspace --all-features --no-run --locked
145+
env:
146+
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
147+
Boost_NO_BOOST_CMAKE: ON
148+
- name: Run tests
149+
run: cargo test --workspace --all-features --verbose
150+
env:
151+
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
152+
Boost_NO_BOOST_CMAKE: ON
153+
124154

125155
wasm-test:
126156
runs-on: ubuntu-latest

crates/analyzer/tests/snapshots/analysis__strings.snap

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/analyzer/tests/analysis.rs
3-
expression: "build_snapshot(\"features/strings.fe\", &src, module, &db)"
3+
expression: "build_snapshot(&files, module_id, &db)"
44

55
---
66
note:
@@ -132,29 +132,26 @@ note:
132132
note:
133133
┌─ features/strings.fe:23:5
134134
135-
23 │ ╭ pub fn return_special_chars() -> String<18>:
136-
24 │ │ return "\n\"'\r\t
137-
25 │ │ foo\\"
138-
│ ╰──────────────^ attributes hash: 14991635520577142188
135+
23 │ ╭ pub fn return_special_chars() -> String<9>:
136+
24 │ │ return "\n\"'\r\tfoo\\"
137+
│ ╰───────────────────────────────^ attributes hash: 2714027657010055129
139138
140139
= FunctionSignature {
141140
self_decl: None,
142141
params: [],
143142
return_type: Ok(
144143
String(
145144
FeString {
146-
max_size: 18,
145+
max_size: 9,
147146
},
148147
),
149148
),
150149
}
151150

152151
note:
153152
┌─ features/strings.fe:24:16
154-
155-
24return "\n\"'\r\t
156-
│ ╭────────────────^
157-
25 │ │ foo\\"
158-
│ ╰──────────────^ String<18>: Memory
153+
154+
24return "\n\"'\r\tfoo\\"
155+
^^^^^^^^^^^^^^^^ String<9>: Memory
159156

160157

crates/parser/src/lexer/token.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub enum TokenKind {
5252
#[regex("0[bB][0-1]+")]
5353
Binary,
5454
// Float,
55-
#[regex(r#""([^"\\]|\\.)*""#)]
56-
#[regex(r#"'([^'\\]|\\.)*'"#)]
55+
#[regex(r#""([^"\\\n]|\\.)*""#)]
56+
#[regex(r#"'([^'\\\n]|\\.)*'"#)]
5757
Text,
5858
#[token("true")]
5959
True,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
contract Foo:
2+
pub fn bar():
3+
let s: String<16> = "This is
4+
Invalid"

crates/test-files/fixtures/features/strings.fe

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ contract Foo:
2020
pub fn return_casted_static_string() -> String<100>:
2121
return String<100>("foo")
2222

23-
pub fn return_special_chars() -> String<18>:
24-
return "\n\"'\r\t
25-
foo\\"
23+
pub fn return_special_chars() -> String<9>:
24+
return "\n\"'\r\tfoo\\"

crates/tests/src/features.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,7 @@ fn strings() {
797797
&mut executor,
798798
"return_special_chars",
799799
&[],
800-
Some(&string_token(
801-
"\n\"'\r\t
802-
foo\\",
803-
)),
800+
Some(&string_token("\n\"'\r\tfoo\\")),
804801
);
805802

806803
harness.events_emitted(
@@ -1696,8 +1693,8 @@ fn abi_decode_checks() {
16961693
// this would break the equivalence of string's `data_offset + data_size` and
16971694
// the bytes' `data_offset`, making the encoding invalid
16981695
tampered_data[byte_index] = 33;
1699-
// the string length is completely valid otherwise. 32 for example will not revert
1700-
// tampered_data[byte_index] = 32;
1696+
// the string length is completely valid otherwise. 32 for example will not
1697+
// revert tampered_data[byte_index] = 32;
17011698
harness.test_call_reverts(&mut executor, tampered_data, &revert_data);
17021699

17031700
// place non-zero byte in padded region of the string

0 commit comments

Comments
 (0)