Skip to content

Commit e36add6

Browse files
russcamswallez
authored andcommitted
Escape HTML characters in docs
This commit escapes HTML characters in docs (<, >, &) so that descriptions display correctly.
1 parent 144f586 commit e36add6

File tree

8 files changed

+28
-8
lines changed

8 files changed

+28
-8
lines changed

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api_generator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ array_tool = "1"
1414
dialoguer = "0.11"
1515
flate2 = "1"
1616
globset = "0.4"
17+
html-escape = "0.2"
1718
indicatif = "0.17"
1819
Inflector = "0.11"
1920
itertools = "0.13"

api_generator/src/generator/code_gen/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ fn doc<I: Into<String>>(comment: I) -> syn::Attribute {
7272
}
7373
}
7474

75+
fn doc_escaped<S: ?Sized + AsRef<str>>(comment: &S) -> syn::Attribute {
76+
doc(html_escape::encode_text(comment))
77+
}
78+
7579
fn stability_doc(stability: Stability) -> Option<syn::Attribute> {
7680
match stability {
7781
Stability::Experimental => Some(doc(r#"&nbsp;

api_generator/src/generator/code_gen/params.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ fn generate_param(tokens: &mut Tokens, e: &ApiEnum) {
6060
})
6161
.unzip();
6262

63-
let doc = e.description.as_ref().map(code_gen::doc);
64-
63+
let doc = e.description.as_ref().map(code_gen::doc_escaped);
6564
let cfg_attr = e.stability.outer_cfg_attr();
6665
let cfg_doc = stability_doc(e.stability);
6766

api_generator/src/generator/code_gen/request/request_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl<'a> RequestBuilder<'a> {
433433
let impl_ident = ident(&name);
434434
let field_ident = ident(&name);
435435
let doc_attr = match &f.1.description {
436-
Some(docs) => vec![doc(docs)],
436+
Some(docs) => vec![doc_escaped(docs)],
437437
_ => vec![],
438438
};
439439

api_generator/src/generator/code_gen/url/enum_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ mod tests {
357357
methods: vec![HttpMethod::Get, HttpMethod::Post],
358358
parts: {
359359
let mut map = BTreeMap::new();
360-
map.insert("index".to_string(), Type {
360+
map.insert("index".to_string(), Type {i
361361
ty: TypeKind::List,
362362
description: Some("A comma-separated list of index names to search".to_string()),
363363
options: vec![],

elasticsearch/src/async_search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ where
802802
self.size = Some(size);
803803
self
804804
}
805-
#[doc = "A comma-separated list of <field>:<direction> pairs"]
805+
#[doc = "A comma-separated list of &lt;field&gt;:&lt;direction&gt; pairs"]
806806
pub fn sort(mut self, sort: &'b [&'b str]) -> Self {
807807
self.sort = Some(sort);
808808
self

elasticsearch/src/root/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ where
17471747
self.slices = Some(slices);
17481748
self
17491749
}
1750-
#[doc = "A comma-separated list of <field>:<direction> pairs"]
1750+
#[doc = "A comma-separated list of &lt;field&gt;:&lt;direction&gt; pairs"]
17511751
pub fn sort(mut self, sort: &'b [&'b str]) -> Self {
17521752
self.sort = Some(sort);
17531753
self
@@ -7275,7 +7275,7 @@ where
72757275
self.size = Some(size);
72767276
self
72777277
}
7278-
#[doc = "A comma-separated list of <field>:<direction> pairs"]
7278+
#[doc = "A comma-separated list of &lt;field&gt;:&lt;direction&gt; pairs"]
72797279
pub fn sort(mut self, sort: &'b [&'b str]) -> Self {
72807280
self.sort = Some(sort);
72817281
self
@@ -9217,7 +9217,7 @@ where
92179217
self.slices = Some(slices);
92189218
self
92199219
}
9220-
#[doc = "A comma-separated list of <field>:<direction> pairs"]
9220+
#[doc = "A comma-separated list of &lt;field&gt;:&lt;direction&gt; pairs"]
92219221
pub fn sort(mut self, sort: &'b [&'b str]) -> Self {
92229222
self.sort = Some(sort);
92239223
self

0 commit comments

Comments
 (0)