@@ -165,121 +165,6 @@ public static bool TryParseStrictList(IList<string>? inputs, [NotNullWhen(true)]
165165 return MultipleValueParser . TryParseStrictValues ( inputs , out parsedValues ) ;
166166 }
167167
168- // name=value; name="value"
169- internal static bool TryGetCookieLength ( StringSegment input , ref int offset , [ NotNullWhen ( true ) ] out CookieHeaderValue ? parsedValue )
170- {
171- Contract . Requires ( offset >= 0 ) ;
172-
173- parsedValue = null ;
174-
175- if ( StringSegment . IsNullOrEmpty ( input ) || ( offset >= input . Length ) )
176- {
177- return false ;
178- }
179-
180- var result = new CookieHeaderValue ( ) ;
181-
182- // The caller should have already consumed any leading whitespace, commas, etc..
183-
184- // Name=value;
185-
186- // Name
187- var itemLength = HttpRuleParser . GetTokenLength ( input , offset ) ;
188- if ( itemLength == 0 )
189- {
190- return false ;
191- }
192- result . _name = input . Subsegment ( offset , itemLength ) ;
193- offset += itemLength ;
194-
195- // = (no spaces)
196- if ( ! ReadEqualsSign ( input , ref offset ) )
197- {
198- return false ;
199- }
200-
201- // value or "quoted value"
202- // The value may be empty
203- result . _value = GetCookieValue ( input , ref offset ) ;
204-
205- parsedValue = result ;
206- return true ;
207- }
208-
209- // cookie-value = *cookie-octet / ( DQUOTE* cookie-octet DQUOTE )
210- // cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
211- // ; US-ASCII characters excluding CTLs, whitespace DQUOTE, comma, semicolon, and backslash
212- internal static StringSegment GetCookieValue ( StringSegment input , ref int offset )
213- {
214- Contract . Requires ( offset >= 0 ) ;
215- Contract . Ensures ( ( Contract . Result < int > ( ) >= 0 ) && ( Contract . Result < int > ( ) <= ( input . Length - offset ) ) ) ;
216-
217- var startIndex = offset ;
218-
219- if ( offset >= input . Length )
220- {
221- return StringSegment . Empty ;
222- }
223- var inQuotes = false ;
224-
225- if ( input [ offset ] == '"' )
226- {
227- inQuotes = true ;
228- offset ++ ;
229- }
230-
231- while ( offset < input . Length )
232- {
233- var c = input [ offset ] ;
234- if ( ! IsCookieValueChar ( c ) )
235- {
236- break ;
237- }
238-
239- offset ++ ;
240- }
241-
242- if ( inQuotes )
243- {
244- if ( offset == input . Length || input [ offset ] != '"' )
245- {
246- // Missing final quote
247- return StringSegment . Empty ;
248- }
249- offset ++ ;
250- }
251-
252- int length = offset - startIndex ;
253- if ( offset > startIndex )
254- {
255- return input . Subsegment ( startIndex , length ) ;
256- }
257-
258- return StringSegment . Empty ;
259- }
260-
261- private static bool ReadEqualsSign ( StringSegment input , ref int offset )
262- {
263- // = (no spaces)
264- if ( offset >= input . Length || input [ offset ] != '=' )
265- {
266- return false ;
267- }
268- offset ++ ;
269- return true ;
270- }
271-
272- // cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
273- // ; US-ASCII characters excluding CTLs, whitespace DQUOTE, comma, semicolon, and backslash
274- private static bool IsCookieValueChar ( char c )
275- {
276- if ( c < 0x21 || c > 0x7E )
277- {
278- return false ;
279- }
280- return ! ( c == '"' || c == ',' || c == ';' || c == '\\ ' ) ;
281- }
282-
283168 internal static void CheckNameFormat ( StringSegment name , string parameterName )
284169 {
285170 if ( name == null )
@@ -301,7 +186,7 @@ internal static void CheckValueFormat(StringSegment value, string parameterName)
301186 }
302187
303188 var offset = 0 ;
304- var result = GetCookieValue ( value , ref offset ) ;
189+ var result = CookieHeaderParserShared . GetCookieValue ( value , ref offset ) ;
305190 if ( result . Length != value . Length )
306191 {
307192 throw new ArgumentException ( "Invalid cookie value: " + value , parameterName ) ;
0 commit comments