Postel’s Law says this: Be generous on input, strict
on output. This means that the code should be tolerant of variations in its input but should be strictly correct when outputting data. As an example, when you accept a boolean as a string, ignore the case and allow it to be expressed as “1, 0, T, F, Y, N,
TRUE, FALSE, YES, NO, etc.”. But when outputting a boolean as a string, stick to one single convention and one single case religiously. [1] So ………… Suppose an application validates XML inputs against
an XML Schema. One part of the schema says that the <isFlyOver> element must contain a Boolean value. Here’s how that element is declared: <xs:element
name="isFlyOver"> That element declaration says XML documents must contain
either this: <isFlyOver>true</isFlyOver> or this: <isFlyOver>false</isFlyOver> Suppose an application receives an XML document containing
this: <isFlyOver>TRUE</isFlyOver> or this: <isFlyOver>1</isFlyOver> Should the application follow Postel’s Law and accept
those XML inputs? And then rebuild the XML so that the output strictly adheres to the schema: <isFlyOver>true</isFlyOver> That is, the application validates inputs against this
slightly looser schema: <xs:element
name="isFlyOver"> If the input validates against that schema, then the
application rebuilds the XML to conform to the strict schema. Thus, if the input arrives as this: <isFlyOver>TRUE</isFlyOver> then the application accepts it and outputs: <isFlyOver>true</isFlyOver> What do you think? Good idea for applications to follow
Postel’s Law? Bad idea? Good in some applications and bad in others? Thoughts? /Roger [1]
http://tedwise.com/2009/05/27/generous-on-input-strict-on-output
|