Skip to content

Commit

Permalink
cli & web v0.0.9: allow DTD, fixes #54
Browse files Browse the repository at this point in the history
  • Loading branch information
sameer committed Mar 29, 2024
1 parent c4e14d0 commit eb9a825
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 19 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "svg2gcode-cli"
version = "0.0.8"
version = "0.0.9"
authors = ["Sameer Puri <[email protected]>"]
edition = "2021"
description = "Command line interface for svg2gcode"
Expand Down
10 changes: 9 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use g_code::{
parse::snippet_parser,
};
use log::info;
use roxmltree::ParsingOptions;
use std::{
env,
fs::File,
Expand Down Expand Up @@ -268,7 +269,14 @@ fn main() -> io::Result<()> {
std::process::exit(1)
};

let document = roxmltree::Document::parse(&input).unwrap();
let document = roxmltree::Document::parse_with_options(
&input,
ParsingOptions {
allow_dtd: true,
..Default::default()
},
)
.unwrap();

let program = svg2program(&document, &settings.conversion, options, machine);

Expand Down
10 changes: 9 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ mod test {
use super::*;
use g_code::emit::{FormatOptions, Token};
use pretty_assertions::assert_eq;
use roxmltree::ParsingOptions;
use svgtypes::{Length, LengthUnit};

/// The values change between debug and release builds for circular interpolation,
Expand All @@ -45,7 +46,14 @@ mod test {
) -> Vec<Token<'_>> {
let config = ConversionConfig::default();
let options = ConversionOptions { dimensions };
let document = roxmltree::Document::parse(input).unwrap();
let document = roxmltree::Document::parse_with_options(
input,
ParsingOptions {
allow_dtd: true,
..Default::default()
},
)
.unwrap();

let machine = Machine::new(
SupportedFunctionality {
Expand Down
2 changes: 1 addition & 1 deletion web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "svg2gcode-web"
version = "0.0.8"
version = "0.0.9"
authors = ["Sameer Puri <[email protected]>"]
edition = "2021"
description = "Convert vector graphics to g-code for pen plotters, laser engravers, and other CNC machines"
Expand Down
22 changes: 19 additions & 3 deletions web/src/forms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use gloo_file::{
futures::read_as_text,
};
use js_sys::TypeError;
use roxmltree::Document;
use roxmltree::{Document, ParsingOptions};
use std::{convert::TryInto, path::Path};
use svg2gcode::Settings;
use wasm_bindgen::JsCast;
Expand Down Expand Up @@ -365,7 +365,15 @@ pub fn svg_form() -> Html {
.await
.map_err(|err| err.to_string())
.and_then(|text| {
if let Some(err) = Document::parse(&text).err() {
if let Some(err) = Document::parse_with_options(
&text,
ParsingOptions {
allow_dtd: true,
..Default::default()
},
)
.err()
{
Err(format!("Error parsing {}: {}", &filename, err))
} else {
Ok(Svg {
Expand Down Expand Up @@ -443,7 +451,15 @@ pub fn svg_form() -> Html {
.unwrap()
.as_string()
.unwrap();
if let Some(err) = Document::parse(&text).err() {
if let Some(err) = Document::parse_with_options(
&text,
ParsingOptions {
allow_dtd: true,
..Default::default()
},
)
.err()
{
url_input_parsed.set(Some(Err(format!(
"Error parsing {}: {}",
&response_url, err
Expand Down
11 changes: 9 additions & 2 deletions web/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use g_code::{
};
use js_sys::Date;
use log::Level;
use roxmltree::Document;
use roxmltree::{Document, ParsingOptions};
use svg2gcode::{svg2program, ConversionOptions, Machine};
use yew::prelude::*;

Expand Down Expand Up @@ -97,7 +97,14 @@ fn app() -> Html {
.transpose()
.unwrap(),
);
let document = Document::parse(svg.content.as_str()).unwrap();
let document = Document::parse_with_options(
svg.content.as_str(),
ParsingOptions {
allow_dtd: true,
..Default::default()
},
)
.unwrap();

let program =
svg2program(&document, &app_store.settings.conversion, options, machine);
Expand Down

0 comments on commit eb9a825

Please sign in to comment.