@@ -731,14 +731,63 @@ public void ObjectTemplateDisplaysSimpleDisplayTextWithNonNullModelTemplateDepth
731
731
public void PasswordTemplateTests ( )
732
732
{
733
733
Assert . Equal (
734
- "<input class=\" text-box single-line password\" id=\" FieldPrefix\" name=\" FieldPrefix\" type=\" password\" value= \" Value \" />" ,
734
+ "<input class=\" text-box single-line password\" id=\" FieldPrefix\" name=\" FieldPrefix\" type=\" password\" />" ,
735
735
DefaultEditorTemplates . PasswordTemplate ( MakeHtmlHelper < string > ( "Value" ) ) ) ;
736
736
737
737
Assert . Equal (
738
- "<input class=\" text-box single-line password\" id=\" FieldPrefix\" name=\" FieldPrefix\" type=\" password\" value= \" <script>alert('XSS!')</script> \" />" ,
738
+ "<input class=\" text-box single-line password\" id=\" FieldPrefix\" name=\" FieldPrefix\" type=\" password\" />" ,
739
739
DefaultEditorTemplates . PasswordTemplate ( MakeHtmlHelper < string > ( "<script>alert('XSS!')</script>" ) ) ) ;
740
740
}
741
741
742
+ [ Fact ]
743
+ public void PasswordTemplate_ReturnsInputElement_IgnoresValues ( )
744
+ {
745
+ // Arrange
746
+ var expected = "<input class=\" text-box single-line password\" id=\" FieldPrefix\" name=\" FieldPrefix\" " +
747
+ "type=\" password\" />" ;
748
+
749
+ // Template ignores Model and FormattedModelValue.
750
+ var helper = MakeHtmlHelper < string > ( model : "Model string" , formattedModelValue : "Formatted string" ) ;
751
+
752
+ var viewData = helper . ViewData ;
753
+ var templateInfo = viewData . TemplateInfo ;
754
+ templateInfo . HtmlFieldPrefix = "FieldPrefix" ;
755
+
756
+ // Template ignores ModelState and ViewData.
757
+ var valueProviderResult = new ValueProviderResult (
758
+ "Raw model string" ,
759
+ "Attempted model string" ,
760
+ CultureInfo . InvariantCulture ) ;
761
+ viewData . ModelState . SetModelValue ( "FieldPrefix" , valueProviderResult ) ;
762
+ viewData [ "FieldPrefix" ] = "ViewData string" ;
763
+
764
+ // Act
765
+ var result = DefaultEditorTemplates . PasswordTemplate ( helper ) ;
766
+
767
+ // Assert
768
+ Assert . Equal ( expected , result ) ;
769
+ }
770
+
771
+ [ Fact ]
772
+ public void PasswordTemplate_ReturnsInputElement_UsesHtmlAttributes ( )
773
+ {
774
+ // Arrange
775
+ var expected = "<input class=\" super text-box single-line password\" id=\" FieldPrefix\" " +
776
+ "name=\" FieldPrefix\" type=\" password\" value=\" Html attributes string\" />" ;
777
+ var helper = MakeHtmlHelper < string > ( model : null ) ;
778
+ var viewData = helper . ViewData ;
779
+ var templateInfo = viewData . TemplateInfo ;
780
+ templateInfo . HtmlFieldPrefix = "FieldPrefix" ;
781
+
782
+ viewData [ "htmlAttributes" ] = new { @class = "super" , value = "Html attributes string" } ;
783
+
784
+ // Act
785
+ var result = DefaultEditorTemplates . PasswordTemplate ( helper ) ;
786
+
787
+ // Assert
788
+ Assert . Equal ( expected , result ) ;
789
+ }
790
+
742
791
public static TheoryDataSet < object , string > PasswordTemplateHtmlAttributeData
743
792
{
744
793
get
@@ -747,11 +796,11 @@ public static TheoryDataSet<object, string> PasswordTemplateHtmlAttributeData
747
796
{
748
797
{
749
798
new { @class = "form-control" } ,
750
- "<input class=\" form-control text-box single-line password\" id=\" FieldPrefix\" name=\" FieldPrefix\" type=\" password\" value= \" Value \" />"
799
+ "<input class=\" form-control text-box single-line password\" id=\" FieldPrefix\" name=\" FieldPrefix\" type=\" password\" />"
751
800
} ,
752
801
{
753
802
new { @class = "form-control" , custom = "foo" } ,
754
- "<input class=\" form-control text-box single-line password\" custom=\" foo\" id=\" FieldPrefix\" name=\" FieldPrefix\" type=\" password\" value= \" Value \" />"
803
+ "<input class=\" form-control text-box single-line password\" custom=\" foo\" id=\" FieldPrefix\" name=\" FieldPrefix\" type=\" password\" />"
755
804
}
756
805
} ;
757
806
}
0 commit comments