mirror of
https://github.com/bitwarden/mobile.git
synced 2024-12-25 16:47:55 +01:00
Fixes for html wrapping and encoding (#746)
This commit is contained in:
parent
25aec80e4c
commit
033b2b9ba0
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Utilities
|
||||
@ -35,6 +36,13 @@ namespace Bit.App.Utilities
|
||||
var specialColor = $"<span style=\"color:#{((Color)Application.Current.Resources["PasswordSpecialColor"]).ToHex().Substring(3)}\">";
|
||||
var result = string.Empty;
|
||||
|
||||
// iOS won't hide the zero-width space char without these div attrs, but Android won't respect
|
||||
// display:inline-block and adds a newline after the password. Hence, only iOS gets the div.
|
||||
if(Device.RuntimePlatform == Device.iOS)
|
||||
{
|
||||
result += "<div style=\"display:inline-block; align-items:center; justify-content:center; text-align:center; word-break:break-all; white-space:pre-wrap; min-width:0\">";
|
||||
}
|
||||
|
||||
// Start with an otherwise uncovered case so we will definitely enter the "something changed"
|
||||
// state.
|
||||
var currentType = CharType.None;
|
||||
@ -83,7 +91,18 @@ namespace Bit.App.Utilities
|
||||
break;
|
||||
}
|
||||
}
|
||||
result += c;
|
||||
|
||||
if(currentType == CharType.Special)
|
||||
{
|
||||
result += HttpUtility.HtmlEncode(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
result += c;
|
||||
}
|
||||
|
||||
// Add zero-width space after every char so per-char wrapping works consistently
|
||||
result += "​";
|
||||
}
|
||||
|
||||
// Close off last span.
|
||||
@ -91,7 +110,13 @@ namespace Bit.App.Utilities
|
||||
{
|
||||
result += "</span>";
|
||||
}
|
||||
|
||||
|
||||
// Close off iOS div
|
||||
if(Device.RuntimePlatform == Device.iOS)
|
||||
{
|
||||
result += "</div>";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user