Skip to content

Commit 54c4736

Browse files
committed
Ensure that an OTP's issuer is correctly escaped when it contains a space
1 parent cecf206 commit 54c4736

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

QRCoder/PayloadGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,11 +2030,11 @@ private void ProcessCommonFields(StringBuilder sb)
20302030

20312031
if (Label != null && Issuer != null)
20322032
{
2033-
label = Issuer + ":" + Label;
2033+
label = escapedIssuer + ":" + Label;
20342034
}
20352035
else if (Issuer != null)
20362036
{
2037-
label = Issuer;
2037+
label = escapedIssuer;
20382038
}
20392039

20402040
if (label != null)

QRCoderTests/PayloadGeneratorTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,6 +2660,21 @@ public void one_time_password_generator_time_based_generates_with_standard_optio
26602660
}
26612661

26622662

2663+
[Fact]
2664+
[Category("PayloadGenerator/OneTimePassword")]
2665+
public void one_time_password_generator_time_based_generates_with_standard_options_escapes_issuer()
2666+
{
2667+
var pg = new PayloadGenerator.OneTimePassword
2668+
{
2669+
Secret = "pwq6 5q55",
2670+
Issuer = "Google Google",
2671+
Label = "[email protected]",
2672+
};
2673+
2674+
pg.ToString().ShouldBe("otpauth://totp/Google%20Google:[email protected]?secret=pwq65q55&issuer=Google%20Google");
2675+
}
2676+
2677+
26632678
[Fact]
26642679
[Category("PayloadGenerator/OneTimePassword")]
26652680
public void one_time_password_generator_hmac_based_generates_with_standard_options()
@@ -2676,6 +2691,22 @@ public void one_time_password_generator_hmac_based_generates_with_standard_optio
26762691
pg.ToString().ShouldBe("otpauth://hotp/Google:[email protected]?secret=pwq65q55&issuer=Google&counter=500");
26772692
}
26782693

2694+
[Fact]
2695+
[Category("PayloadGenerator/OneTimePassword")]
2696+
public void one_time_password_generator_hmac_based_generates_with_standard_options_escapes_issuer()
2697+
{
2698+
var pg = new PayloadGenerator.OneTimePassword
2699+
{
2700+
Secret = "pwq6 5q55",
2701+
Issuer = "Google Google",
2702+
Label = "[email protected]",
2703+
Type = PayloadGenerator.OneTimePassword.OneTimePasswordAuthType.HOTP,
2704+
Counter = 500,
2705+
};
2706+
2707+
pg.ToString().ShouldBe("otpauth://hotp/Google%20Google:[email protected]?secret=pwq65q55&issuer=Google%20Google&counter=500");
2708+
}
2709+
26792710

26802711
[Fact]
26812712
[Category("PayloadGenerator/ShadowSocksConfig")]

0 commit comments

Comments
 (0)