Skip to content

Commit 71cdc3d

Browse files
committed
(#154) Api: avoid invalid XML comments
1 parent 060e4c6 commit 71cdc3d

File tree

7 files changed

+26
-9
lines changed

7 files changed

+26
-9
lines changed

TdLib.Api/Functions/CancelPasswordReset.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace TdLib
1010
public static partial class TdApi
1111
{
1212
/// <summary>
13-
/// Cancels reset of 2-step verification password. The method can be called if passwordState.pending_reset_date > 0
13+
/// Cancels reset of 2-step verification password. The method can be called if passwordState.pending_reset_date &gt; 0
1414
/// </summary>
1515
public class CancelPasswordReset : Function<Ok>
1616
{
@@ -30,7 +30,7 @@ public class CancelPasswordReset : Function<Ok>
3030
}
3131

3232
/// <summary>
33-
/// Cancels reset of 2-step verification password. The method can be called if passwordState.pending_reset_date > 0
33+
/// Cancels reset of 2-step verification password. The method can be called if passwordState.pending_reset_date &gt; 0
3434
/// </summary>
3535
public static Task<Ok> CancelPasswordResetAsync(
3636
this Client client)

TdLib.Api/Functions/CreateNewStickerSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class CreateNewStickerSet : Function<StickerSet>
4141
public string Title { get; set; }
4242

4343
/// <summary>
44-
/// Sticker set name. Can contain only English letters, digits and underscores. Must end with *"_by_<bot username>"* (*<bot_username>* is case insensitive) for bots; 1-64 characters
44+
/// Sticker set name. Can contain only English letters, digits and underscores. Must end with *"_by_&lt;bot username&gt;"* (*&lt;bot_username&gt;* is case insensitive) for bots; 1-64 characters
4545
/// </summary>
4646
[JsonConverter(typeof(Converter))]
4747
[JsonProperty("name")]

TdLib.Api/Objects/PageBlockCaption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public partial class PageBlockCaption : Object
3333
public RichText Text { get; set; }
3434

3535
/// <summary>
36-
/// Block credit (like HTML tag <cite>)
36+
/// Block credit (like HTML tag &lt;cite&gt;)
3737
/// </summary>
3838
[JsonConverter(typeof(Converter))]
3939
[JsonProperty("credit")]

TdLib.Api/Objects/PhoneNumberAuthenticationSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public partial class PhoneNumberAuthenticationSettings : Object
4747
public bool IsCurrentPhoneNumber { get; set; }
4848

4949
/// <summary>
50-
/// For official applications only. True, if the application can use Android SMS Retriever API (requires Google Play Services >= 10.2) to automatically receive the authentication code from the SMS. See https://developers.google.com/identity/sms-retriever/ for more details
50+
/// For official applications only. True, if the application can use Android SMS Retriever API (requires Google Play Services &gt;= 10.2) to automatically receive the authentication code from the SMS. See https://developers.google.com/identity/sms-retriever/ for more details
5151
/// </summary>
5252
[JsonConverter(typeof(Converter))]
5353
[JsonProperty("allow_sms_retriever_api")]

TdLib.Api/Objects/SecretChat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public partial class SecretChat : Object
6161
public byte[] KeyHash { get; set; }
6262

6363
/// <summary>
64-
/// Secret chat layer; determines features supported by the chat partner's application. Nested text entities and underline and strikethrough entities are supported if the layer >= 101, files bigger than 2000MB are supported if the layer >= 143, spoiler and custom emoji text entities are supported if the layer >= 144
64+
/// Secret chat layer; determines features supported by the chat partner's application. Nested text entities and underline and strikethrough entities are supported if the layer &gt;= 101, files bigger than 2000MB are supported if the layer &gt;= 143, spoiler and custom emoji text entities are supported if the layer &gt;= 144
6565
/// </summary>
6666
[JsonConverter(typeof(Converter))]
6767
[JsonProperty("layer")]

TdLib.CodeGen/Generator.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ let generateField (def: Parser.TlDef) (field: Parser.TlField) (annotations: Pars
6565

6666
let lines = Utils.readResource "Field.tpl"
6767
lines |> Seq.map (fun line ->
68-
tabulation + line.Replace("$FIELD_DESCRIPTION", description)
68+
tabulation + line.Replace("$FIELD_DESCRIPTION", Utils.xmlEncode description)
6969
.Replace("$FIELD_ATTRIBUTES", fieldAttributes)
7070
.Replace("$FIELD_TYPE", fieldType)
7171
.Replace("$FIELD_NAME", fieldName))
@@ -93,7 +93,7 @@ let generateType (def: Parser.TlDef) (annotations: Parser.TlAnnotation list) =
9393

9494
let lines = Utils.readResource (if isObjectType then "Object.tpl" else "Union.tpl")
9595
lines |> Seq.map (fun line ->
96-
line.Replace("$TYPE_DESCRIPTION", description)
96+
line.Replace("$TYPE_DESCRIPTION", Utils.xmlEncode description)
9797
.Replace("$TYPE_NAME", objectTypeName)
9898
.Replace("$TL_TYPE_NAME", tlTypeName)
9999
.Replace("$BASE_TYPE_NAME", baseTypeName)
@@ -132,7 +132,7 @@ let generateFunc (def: Parser.TlDef) (annotations: Parser.TlAnnotation list) =
132132

133133
let lines = Utils.readResource "Function.tpl"
134134
lines |> Seq.map (fun line ->
135-
line.Replace("$FUNC_DESCRIPTION", description)
135+
line.Replace("$FUNC_DESCRIPTION", Utils.xmlEncode description)
136136
.Replace("$FUNC_NAME", funcTypeName)
137137
.Replace("$TL_FUNC_NAME", tlFuncTypeName)
138138
.Replace("$RETURN_TYPE_NAME", returnTypeName)

TdLib.CodeGen/Utils.fs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
open System
44
open System.IO
55
open System.Reflection
6+
open System.Xml.Linq
7+
68
open Xunit
79

810
type Case =
@@ -34,6 +36,9 @@ let readResource res = seq {
3436
yield reader.ReadLine()
3537
}
3638

39+
let xmlEncode(str: string): string =
40+
if str = "" then ""
41+
else XElement("x", str).LastNode.ToString()
3742

3843
[<Fact>]
3944
let ``toCamelCase converts string to upper camel case``() =
@@ -58,3 +63,15 @@ let ``readResource reads file from embedded resources``() =
5863
let lines = readResource "Object.tpl"
5964
let first = Seq.head lines
6065
Assert.Equal("using System;", first)
66+
67+
[<Fact>]
68+
let ``xmlEncode doesn't fail for an empty string``(): unit =
69+
let original = ""
70+
let encoded = xmlEncode original
71+
Assert.Equal("", encoded)
72+
73+
[<Fact>]
74+
let ``xmlEncode encodes XML``(): unit =
75+
let original = "<html> test"
76+
let encoded = xmlEncode original
77+
Assert.Equal("&lt;html&gt; test", encoded)

0 commit comments

Comments
 (0)