ohos: Improve argument filtering (#34422)

This avoids future crashes if new unknown parameters
are passed by the runtime to the app.
It does make it slightly more inconvenient for the user,
since they must use `=` and space at the right place now.
This will also be updated in the book accordingly

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
Jonathan Schwender 2024-12-02 09:17:53 +01:00 committed by GitHub
parent e9c7c04def
commit bb1d2bd0f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,18 +12,27 @@ export default class EntryAbility extends UIAbility {
if (typeof want.parameters !== "undefined") { if (typeof want.parameters !== "undefined") {
Object.entries(want.parameters).forEach((entry) => { Object.entries(want.parameters).forEach((entry) => {
let key = entry[0] let key = entry[0]
// Skip some default parameters, since servo is not interested in those // The commandline parameters we are interested in all start with `--`.
if (key.startsWith("ohos.") // OpenHarmony also adds quite a few default parameters to the wants.parameters
|| key.startsWith("component.") // dictionary, and servo currently fails with an error if it receives unknown
|| key.startsWith("send_to_erms_") // options.
|| key === "isCallBySCB" // On the commandline you can pass parameters via the `aa` tool.
|| key === "moduleName" // ```
|| key === "debugApp" // aa start -a EntryAbility -b org.servo.servoshell --ps=--screen-size 505x413
) { // ```
return // Use `--ps=--arg_name value` for key-value parameters. Please note that
// `--ps` and `--<arg_name>` must be connected by an `=` and may not be seperated.
// the value must be space seperated, since `aa start` will expect it as a second parameter.
// Use `--psn=--arg_name` for flags that do not have a value.
// See the aa tool documentation for more details:
// https://docs.openharmony.cn/pages/v5.0/en/application-dev/tools/aa-tool.md
if (key.startsWith("--")) {
let value = entry[1].toString()
params.push(key)
if (value) {
params.push(value)
}
} }
let value = entry[1]
params.push("--" + key + "=" + value.toString())
}) })
} }
let servoshell_params = params.join("\u{001f}") let servoshell_params = params.join("\u{001f}")