Skip to content

WASIp3 HTTP: Inconsistent errors when adding invalid field names #11771

@wingo

Description

@wingo

Consider this test for what the HTTP implementation does with invalid field names. First it tries a field name with a space in it, then it tries ". Both of these are invalid, but the first shows an error on fields.delete whereas the second does not:

extern crate wit_bindgen;

wit_bindgen::generate!({
    inline: r"
  package test:test;

  world test {
      include wasi:http/[email protected];
  }
",
    additional_derives: [PartialEq, Eq, Hash, Clone],
    features:["clocks-timezone"],
    generate_all
});

use wasi::http::types::Fields;
use wasi::http::types::HeaderError;

fn test_invalid_field_name(field: &str) {
    println!("testing field: {}", field);
    let fields = Fields::new();
    assert!(!fields.has(field));
    assert_eq!(fields.delete(field),
               Err(HeaderError::InvalidSyntax));
}

fn test_invalid_field_names() {
    test_invalid_field_name("field with space");
    test_invalid_field_name("\"");
}

fn main() {
    test_invalid_field_names();
}

Run it:

$ cargo +nightly build --target=wasm32-wasip2 --release && wasmtime -Wcomponent-model-async -Sp3,http target/wasm32-wasip2/release/field-invalid.wasm
   Compiling test-wasm32-wasip3 v0.1.0 (/home/wingo/src/wasip3/wasi-testsuite/tests/rust/wasm32-wasip3)
    Finished `release` profile [optimized] target(s) in 0.35s
testing field: field with space
testing field: "

thread 'main' (1) panicked at src/bin/field-invalid.rs:23:5:
assertion `left == right` failed
  left: Ok(())
 right: Err(HeaderError::InvalidSyntax)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior in the current implementation that needs fixingwasi:implIssues pertaining to WASI implementation in Wasmtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions