forked from microsoft/regorus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Skip recording undefined variables 2. Parse `in` correctly if it is not imported. 3. base64.decode Signed-off-by: Anand Krishnamoorthi <[email protected]>
- Loading branch information
Showing
7 changed files
with
61 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
use crate::ast::Expr; | ||
use crate::builtins; | ||
use crate::builtins::utils::{ensure_args_count, ensure_string}; | ||
use crate::lexer::Span; | ||
use crate::value::Value; | ||
|
||
use std::collections::HashMap; | ||
|
||
use anyhow::Result; | ||
use data_encoding::BASE64; | ||
|
||
pub fn register(m: &mut HashMap<&'static str, builtins::BuiltinFcn>) { | ||
m.insert("base64.decode", (base64_decode, 1)); | ||
} | ||
|
||
fn base64_decode(span: &Span, params: &[Expr], args: &[Value]) -> Result<Value> { | ||
let name = "base64.decode"; | ||
ensure_args_count(span, name, params, args, 1)?; | ||
|
||
let encoded_str = ensure_string(name, ¶ms[0], &args[0])?; | ||
let decoded_bytes = BASE64.decode(encoded_str.as_bytes())?; | ||
Ok(Value::String( | ||
String::from_utf8_lossy(&decoded_bytes).to_string(), | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters