mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 23:25:45 +03:00
Fixes for html wrapping and encoding (#746)
This commit is contained in:
parent
25aec80e4c
commit
033b2b9ba0
1 changed files with 27 additions and 2 deletions
|
@ -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.
|
||||
|
@ -92,6 +111,12 @@ namespace Bit.App.Utilities
|
|||
result += "</span>";
|
||||
}
|
||||
|
||||
// Close off iOS div
|
||||
if(Device.RuntimePlatform == Device.iOS)
|
||||
{
|
||||
result += "</div>";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue