Skip to content

Commit

Permalink
avm2: Verify the URLRequest method
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie committed Feb 6, 2024
1 parent 4c6f2ba commit cadae93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 2 additions & 3 deletions core/src/avm2/globals/flash/display/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ pub fn request_from_url_request<'gc>(
string_headers.insert(name, value);
}

// TODO: URLRequest.method should not be able to have invalid types.
// We should throw an error there on set.
let method = NavigationMethod::from_method_str(&method).unwrap_or(NavigationMethod::Get);
let method =
NavigationMethod::from_method_str(&method).expect("URLRequest should have a valid method");
let data = url_request.get_public_property("data", activation)?;
let body = match (method, data) {
(_, Value::Null | Value::Undefined) => None,
Expand Down
12 changes: 8 additions & 4 deletions core/src/avm2/globals/flash/net/URLRequest.as
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package flash.net {
// FIXME - this should be a getter/setter for consistency with Flash
public var url:String;
private var _contentType: String = "application/x-www-form-urlencoded"; // ignored

private var _requestHeaders: Array = [];

public var digest:String;
Expand All @@ -25,9 +24,14 @@ package flash.net {
return this._method;
}

public function set method(newMethod:String):void {
// FIXME - perform validation here
this._method = newMethod;
public function set method(value: String):void {
// The method can apparently either be all upper or lower case, but not mixed.
if (value !== "GET" && value !== "get" && value !== "POST" && value !== "post") {
throw new ArgumentError("Error #2008: Parameter method must be one of the accepted values.", 2008);
}

// TODO: AIR is supposed to support other methods like PUT or DELETE.
this._method = value;
}

public function get data():Object {
Expand Down

0 comments on commit cadae93

Please sign in to comment.