From a0d9047faf7de2c3fadf81cda2644632f2a9eedf Mon Sep 17 00:00:00 2001 From: gluax Date: Thu, 1 Jul 2021 13:59:56 -0700 Subject: [PATCH] validate that a package being published doesn't conflict with keywords --- Cargo.lock | 1 + Cargo.toml | 4 ++++ leo/commands/package/publish.rs | 5 +++++ parser/src/lib.rs | 1 + parser/src/tokenizer/mod.rs | 1 + 5 files changed, 12 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b07391f0bd..4195c44ec9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1222,6 +1222,7 @@ dependencies = [ "leo-imports", "leo-input", "leo-package", + "leo-parser", "leo-state", "leo-synthesizer", "notify", diff --git a/Cargo.toml b/Cargo.toml index b47de38dcd..5720496db4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,6 +61,10 @@ version = "1.5.2" path = "./package" version = "1.5.2" +[dependencies.leo-parser] +path = "./parser" +version = "1.5.2" + [dependencies.leo-state] path = "./state" version = "1.5.2" diff --git a/leo/commands/package/publish.rs b/leo/commands/package/publish.rs index 213ce26340..a3d7f165c7 100644 --- a/leo/commands/package/publish.rs +++ b/leo/commands/package/publish.rs @@ -20,6 +20,7 @@ use leo_package::{ outputs::OutputsDirectory, root::{ZipFile, AUTHOR_PLACEHOLDER}, }; +use leo_parser::KEYWORD_TOKENS; use anyhow::{anyhow, Result}; use structopt::StructOpt; @@ -47,6 +48,10 @@ impl Command for Publish { let manifest = context.manifest()?; let package_name = manifest.get_package_name(); + if KEYWORD_TOKENS.iter().any(|keyword| keyword.to_string() == package_name) { + return Err(anyhow!("Cannot name a package after a keyword")); + } + let package_version = manifest.get_package_version(); match ( diff --git a/parser/src/lib.rs b/parser/src/lib.rs index 2e32c5ab4f..b896eee0b8 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -25,6 +25,7 @@ extern crate thiserror; pub(crate) mod tokenizer; +pub use tokenizer::KEYWORD_TOKENS; pub(crate) use tokenizer::*; pub mod errors; diff --git a/parser/src/tokenizer/mod.rs b/parser/src/tokenizer/mod.rs index adfcbb22e5..5da374e575 100644 --- a/parser/src/tokenizer/mod.rs +++ b/parser/src/tokenizer/mod.rs @@ -22,6 +22,7 @@ pub(crate) mod token; use std::sync::Arc; +pub use self::token::KEYWORD_TOKENS; pub(crate) use self::token::*; pub(crate) mod lexer;