@@ -731,14 +731,63 @@ public void ObjectTemplateDisplaysSimpleDisplayTextWithNonNullModelTemplateDepth
731731 public void PasswordTemplateTests ( )
732732 {
733733 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\" />" ,
735735 DefaultEditorTemplates . PasswordTemplate ( MakeHtmlHelper < string > ( "Value" ) ) ) ;
736736
737737 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\" />" ,
739739 DefaultEditorTemplates . PasswordTemplate ( MakeHtmlHelper < string > ( "<script>alert('XSS!')</script>" ) ) ) ;
740740 }
741741
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+
742791 public static TheoryDataSet < object , string > PasswordTemplateHtmlAttributeData
743792 {
744793 get
@@ -747,11 +796,11 @@ public static TheoryDataSet<object, string> PasswordTemplateHtmlAttributeData
747796 {
748797 {
749798 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\" />"
751800 } ,
752801 {
753802 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\" />"
755804 }
756805 } ;
757806 }
0 commit comments