Skip to content

Commit

Permalink
Forbid newline in string literal
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Nak committed Feb 7, 2022
1 parent f3a51c3 commit 49f68de
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 24 deletions.
35 changes: 33 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ jobs:
- os: macOS-latest
steps:
- uses: actions/checkout@v2
- name: Install Mac System dependencies
- name: Install Boost on Mac
if: startsWith(matrix.os,'macOS')
run: |
brew install boost
- name: Install Linux dependencies
- name: Install Boost on Linux
if: startsWith(matrix.os,'ubuntu')
run: |
sudo apt-get install -y libboost-all-dev
Expand All @@ -121,6 +121,37 @@ jobs:
run: cargo test --workspace --all-features --no-run --locked
- name: Run tests
run: cargo test --workspace --all-features --verbose

test-windows-latest:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Install Boost on Windows.
uses: MarkusJx/install-boost@v2.1.0
id: install-boost
with:
boost_version: 1.78.0
platform_version: 2019
toolset: msvc
- name: Install rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Cache Dependencies
uses: Swatinem/rust-cache@v1
- name: Build
run: cargo test --workspace --all-features --no-run --locked
env:
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
Boost_NO_BOOST_CMAKE: ON
- name: Run tests
run: cargo test --workspace --all-features --verbose
env:
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
Boost_NO_BOOST_CMAKE: ON


wasm-test:
runs-on: ubuntu-latest
Expand Down
19 changes: 8 additions & 11 deletions crates/analyzer/tests/snapshots/analysis__strings.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/analyzer/tests/analysis.rs
expression: "build_snapshot(\"features/strings.fe\", &src, module, &db)"
expression: "build_snapshot(&files, module_id, &db)"

---
note:
Expand Down Expand Up @@ -132,29 +132,26 @@ note:
note:
┌─ features/strings.fe:23:5
23 │ ╭ pub fn return_special_chars() -> String<18>:
24 │ │ return "\n\"'\r\t
25 │ │ foo\\"
│ ╰──────────────^ attributes hash: 14991635520577142188
23 │ ╭ pub fn return_special_chars() -> String<9>:
24 │ │ return "\n\"'\r\tfoo\\"
│ ╰───────────────────────────────^ attributes hash: 2714027657010055129
= FunctionSignature {
self_decl: None,
params: [],
return_type: Ok(
String(
FeString {
max_size: 18,
max_size: 9,
},
),
),
}

note:
┌─ features/strings.fe:24:16
24return "\n\"'\r\t
│ ╭────────────────^
25 │ │ foo\\"
│ ╰──────────────^ String<18>: Memory
24return "\n\"'\r\tfoo\\"
^^^^^^^^^^^^^^^^ String<9>: Memory


4 changes: 2 additions & 2 deletions crates/parser/src/lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub enum TokenKind {
#[regex("0[bB][0-1]+")]
Binary,
// Float,
#[regex(r#""([^"\\]|\\.)*""#)]
#[regex(r#"'([^'\\]|\\.)*'"#)]
#[regex(r#""([^"\\\n]|\\.)*""#)]
#[regex(r#"'([^'\\\n]|\\.)*'"#)]
Text,
#[token("true")]
True,
Expand Down
4 changes: 4 additions & 0 deletions crates/test-files/fixtures/compile_errors/string_literal.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
contract Foo:
pub fn bar():
let s: String<16> = "This is
Invalid"
5 changes: 2 additions & 3 deletions crates/test-files/fixtures/features/strings.fe
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ contract Foo:
pub fn return_casted_static_string() -> String<100>:
return String<100>("foo")

pub fn return_special_chars() -> String<18>:
return "\n\"'\r\t
foo\\"
pub fn return_special_chars() -> String<9>:
return "\n\"'\r\tfoo\\"
9 changes: 3 additions & 6 deletions crates/tests/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,7 @@ fn strings() {
&mut executor,
"return_special_chars",
&[],
Some(&string_token(
"\n\"'\r\t
foo\\",
)),
Some(&string_token("\n\"'\r\tfoo\\")),
);

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

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

0 comments on commit 49f68de

Please sign in to comment.