readAttrValue reads an attribute value.
()
| 331 | |
| 332 | // readAttrValue reads an attribute value. |
| 333 | func (d *Decoder) readAttrValue() ([]byte, bool) { |
| 334 | d.buf.Reset() |
| 335 | |
| 336 | b, ok := d.mustReadByte() |
| 337 | if !ok { |
| 338 | return nil, false |
| 339 | } |
| 340 | |
| 341 | if b == '"' || b == '\'' { |
| 342 | // Quoted attribute value |
| 343 | // We can just read until the closing quote. |
| 344 | if !d.mustReadUntil(b) { |
| 345 | return nil, false |
| 346 | } |
| 347 | // Remove the trailing quote from the buffer |
| 348 | d.buf.Remove(1) |
| 349 | } else { |
| 350 | // Unquoted attribute value. |
| 351 | // Unread the byte for further processing |
| 352 | d.unreadByte(b) |
| 353 | // Read until we meet a byte that is not valid in an unquoted attribute value. |
| 354 | if !d.mustReadWhileFn(isValueByte) { |
| 355 | return nil, false |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | return d.buf.Bytes(), true |
| 360 | } |
| 361 | |
| 362 | // isValueByte checks if a byte is valid in an unquoted attribute value. |
| 363 | // See: https://www.w3.org/TR/REC-html40/intro/sgmltut.html#h-3.2.2 |
no test coverage detected