| 844 | } |
| 845 | |
| 846 | func (d *Decoder) attrval() []byte { |
| 847 | b, ok := d.mustgetc() |
| 848 | if !ok { |
| 849 | return nil |
| 850 | } |
| 851 | // Handle quoted attribute values |
| 852 | if b == '"' || b == '\'' { |
| 853 | return d.text(int(b), false) |
| 854 | } |
| 855 | // Handle unquoted attribute values for strict parsers |
| 856 | if d.Strict { |
| 857 | d.err = d.syntaxError("unquoted or missing attribute value in element") |
| 858 | return nil |
| 859 | } |
| 860 | // Handle unquoted attribute values for unstrict parsers |
| 861 | d.ungetc(b) |
| 862 | d.buf.Reset() |
| 863 | for { |
| 864 | b, ok = d.mustgetc() |
| 865 | if !ok { |
| 866 | return nil |
| 867 | } |
| 868 | // https://www.w3.org/TR/REC-html40/intro/sgmltut.html#h-3.2.2 |
| 869 | if 'a' <= b && b <= 'z' || 'A' <= b && b <= 'Z' || |
| 870 | '0' <= b && b <= '9' || b == '_' || b == ':' || b == '-' { |
| 871 | d.buf.WriteByte(b) |
| 872 | } else { |
| 873 | d.ungetc(b) |
| 874 | break |
| 875 | } |
| 876 | } |
| 877 | return d.buf.Bytes() |
| 878 | } |
| 879 | |
| 880 | // Skip spaces if any |
| 881 | func (d *Decoder) space() { |