@@ -7,48 +7,31 @@ use serde::{de::Error as DeError, Deserialize, Deserializer};
77use std:: path:: PathBuf ;
88
99/// A command allowed to be executed by the webview API.
10- #[ derive( Debug , Clone , PartialEq , Eq , Hash , schemars :: JsonSchema ) ]
11- pub struct Entry {
12- /// The name for this allowed shell command configuration.
13- ///
14- /// This name will be used inside of the webview API to call this command along with
15- /// any specified arguments.
16- pub name : String ,
10+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
11+ pub ( crate ) struct Entry {
12+ pub ( crate ) name : String ,
13+ pub ( crate ) command : PathBuf ,
14+ pub ( crate ) args : ShellAllowedArgs ,
15+ pub ( crate ) sidecar : bool ,
16+ }
1717
18- /// The command name.
19- /// It can start with a variable that resolves to a system base directory.
20- /// The variables are: `$AUDIO`, `$CACHE`, `$CONFIG`, `$DATA`, `$LOCALDATA`, `$DESKTOP`,
21- /// `$DOCUMENT`, `$DOWNLOAD`, `$EXE`, `$FONT`, `$HOME`, `$PICTURE`, `$PUBLIC`, `$RUNTIME`,
22- /// `$TEMPLATE`, `$VIDEO`, `$RESOURCE`, `$LOG`, `$TEMP`, `$APPCONFIG`, `$APPDATA`,
23- /// `$APPLOCALDATA`, `$APPCACHE`, `$APPLOG`.
24- // use default just so the schema doesn't flag it as required
18+ #[ derive( Deserialize ) ]
19+ pub ( crate ) struct EntryRaw {
20+ pub ( crate ) name : String ,
2521 #[ serde( rename = "cmd" ) ]
26- pub command : PathBuf ,
27-
28- /// The allowed arguments for the command execution.
29- pub args : ShellAllowedArgs ,
30-
31- /// If this command is a sidecar command.
32- pub sidecar : bool ,
22+ pub ( crate ) command : Option < PathBuf > ,
23+ #[ serde( default ) ]
24+ pub ( crate ) args : ShellAllowedArgs ,
25+ #[ serde( default ) ]
26+ pub ( crate ) sidecar : bool ,
3327}
3428
3529impl < ' de > Deserialize < ' de > for Entry {
3630 fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
3731 where
3832 D : Deserializer < ' de > ,
3933 {
40- #[ derive( Deserialize ) ]
41- struct InnerEntry {
42- name : String ,
43- #[ serde( rename = "cmd" ) ]
44- command : Option < PathBuf > ,
45- #[ serde( default ) ]
46- args : ShellAllowedArgs ,
47- #[ serde( default ) ]
48- sidecar : bool ,
49- }
50-
51- let config = InnerEntry :: deserialize ( deserializer) ?;
34+ let config = EntryRaw :: deserialize ( deserializer) ?;
5235
5336 if !config. sidecar && config. command . is_none ( ) {
5437 return Err ( DeError :: custom (
@@ -65,19 +48,11 @@ impl<'de> Deserialize<'de> for Entry {
6548 }
6649}
6750
68- /// A set of command arguments allowed to be executed by the webview API.
69- ///
70- /// A value of `true` will allow any arguments to be passed to the command. `false` will disable all
71- /// arguments. A list of [`ShellAllowedArg`] will set those arguments as the only valid arguments to
72- /// be passed to the attached command configuration.
73- #[ derive( Debug , PartialEq , Eq , Clone , Hash , Deserialize , schemars:: JsonSchema ) ]
51+ #[ derive( Debug , PartialEq , Eq , Clone , Hash , Deserialize ) ]
7452#[ serde( untagged, deny_unknown_fields) ]
7553#[ non_exhaustive]
7654pub enum ShellAllowedArgs {
77- /// Use a simple boolean to allow all or disable all arguments to this command configuration.
7855 Flag ( bool ) ,
79-
80- /// A specific set of [`ShellAllowedArg`] that are valid to call for the command configuration.
8156 List ( Vec < ShellAllowedArg > ) ,
8257}
8358
@@ -87,33 +62,13 @@ impl Default for ShellAllowedArgs {
8762 }
8863}
8964
90- /// A command argument allowed to be executed by the webview API.
91- #[ derive( Debug , PartialEq , Eq , Clone , Hash , Deserialize , schemars:: JsonSchema ) ]
65+ #[ derive( Debug , PartialEq , Eq , Clone , Hash , Deserialize ) ]
9266#[ serde( untagged, deny_unknown_fields) ]
9367#[ non_exhaustive]
9468pub enum ShellAllowedArg {
95- /// A non-configurable argument that is passed to the command in the order it was specified.
9669 Fixed ( String ) ,
97-
98- /// A variable that is set while calling the command from the webview API.
99- ///
10070 Var {
101- /// [regex] validator to require passed values to conform to an expected input.
102- ///
103- /// This will require the argument value passed to this variable to match the `validator` regex
104- /// before it will be executed.
105- ///
106- /// The regex string is by default surrounded by `^...$` to match the full string.
107- /// For example the `https?://\w+` regex would be registered as `^https?://\w+$`.
108- ///
109- /// [regex]: <https://docs.rs/regex/latest/regex/#syntax>
11071 validator : String ,
111-
112- /// Marks the validator as a raw regex, meaning the plugin should not make any modification at runtime.
113- ///
114- /// This means the regex will not match on the entire string by default, which might
115- /// be exploited if your regex allow unexpected input to be considered valid.
116- /// When using this option, make sure your regex is correct.
11772 #[ serde( default ) ]
11873 raw : bool ,
11974 } ,
0 commit comments