diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-30 18:54:39 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-12-05 02:52:36 +0100 |
commit | 042409a2c40bb997739326928eab7d0430cec50b (patch) | |
tree | f7566682a4a75d24dc33924fa7f985c68605558f /src | |
parent | fff865a98aa288930d6e363f03ad57570e429e92 (diff) |
spans: fix spans for quoted attribute values
Diffstat (limited to 'src')
-rw-r--r-- | src/emitter.rs | 4 | ||||
-rw-r--r-- | src/machine.rs | 6 | ||||
-rw-r--r-- | src/spans.rs | 5 |
3 files changed, 9 insertions, 6 deletions
diff --git a/src/emitter.rs b/src/emitter.rs index 1ab01f0..48ac391 100644 --- a/src/emitter.rs +++ b/src/emitter.rs @@ -132,9 +132,11 @@ pub trait Emitter<R> { fn init_attribute_name(&mut self, reader: &R); /// Called before the first push_attribute_value call. + /// If the value is wrappend in double or single quotes `quoted` is set to true, otherwise false. /// /// If there is no current attribute, this method may panic. - fn init_attribute_value(&mut self, #[allow(unused_variables)] reader: &R) {} + #[allow(unused_variables)] + fn init_attribute_value(&mut self, reader: &R, quoted: bool) {} /// Append a string to the current attribute's name. /// diff --git a/src/machine.rs b/src/machine.rs index 80b37d6..4300f45 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -763,12 +763,12 @@ pub fn consume<R: Reader, E: Emitter<R>>( State::BeforeAttributeValue => match slf.read_char()? { Some(whitespace_pat!()) => Ok(ControlToken::Continue), Some('"') => { - slf.emitter.init_attribute_value(&slf.reader); + slf.emitter.init_attribute_value(&slf.reader, true); slf.state = State::AttributeValueDoubleQuoted; Ok(ControlToken::Continue) } Some('\'') => { - slf.emitter.init_attribute_value(&slf.reader); + slf.emitter.init_attribute_value(&slf.reader, true); slf.state = State::AttributeValueSingleQuoted; Ok(ControlToken::Continue) } @@ -779,7 +779,7 @@ pub fn consume<R: Reader, E: Emitter<R>>( Ok(ControlToken::Continue) } c => { - slf.emitter.init_attribute_value(&slf.reader); + slf.emitter.init_attribute_value(&slf.reader, false); slf.state = State::AttributeValueUnquoted; slf.unread_char(c); Ok(ControlToken::Continue) diff --git a/src/spans.rs b/src/spans.rs index ab455f9..6d7c18e 100644 --- a/src/spans.rs +++ b/src/spans.rs @@ -273,9 +273,10 @@ impl<R: GetPos> Emitter<R> for SpanEmitter<R> { )); } - fn init_attribute_value(&mut self, reader: &R) { + fn init_attribute_value(&mut self, reader: &R, quoted: bool) { let current_attr = self.current_attribute.as_mut().unwrap(); - current_attr.1.value_span = reader.get_pos() - 1..reader.get_pos() - 1; + let offset = if quoted { 0 } else { 1 }; + current_attr.1.value_span = reader.get_pos() - offset..reader.get_pos() - offset; } fn push_attribute_name(&mut self, s: &str) { |