From 01fa1513f4bd6f194bf6d1ca17e510003fa23312 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Sat, 17 Sep 2016 14:49:23 +0200 Subject: [PATCH] Lexing of processing instructions with namespaces This adds lexing/parsing support for processing instructions that contain namespace prefixes such as ``. --- ext/ragel/base_lexer.rl | 2 +- spec/oga/xml/lexer/processing_instruction_spec.rb | 8 ++++++++ spec/oga/xml/parser/processing_instruction_spec.rb | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ext/ragel/base_lexer.rl b/ext/ragel/base_lexer.rl index d5f8070..0e552b4 100644 --- a/ext/ragel/base_lexer.rl +++ b/ext/ragel/base_lexer.rl @@ -161,7 +161,7 @@ # instruction. # - proc_ins_start = ''; # Everything except "?" OR a single "?" diff --git a/spec/oga/xml/lexer/processing_instruction_spec.rb b/spec/oga/xml/lexer/processing_instruction_spec.rb index 0803032..46219da 100644 --- a/spec/oga/xml/lexer/processing_instruction_spec.rb +++ b/spec/oga/xml/lexer/processing_instruction_spec.rb @@ -70,6 +70,14 @@ describe Oga::XML::Lexer do ] end + it 'lexes an instruction with a namespace prefix' do + lex('').should == [ + [:T_PROC_INS_START, nil, 1], + [:T_PROC_INS_NAME, 'foo:bar', 1], + [:T_PROC_INS_END, nil, 1] + ] + end + describe 'using an IO as input' do it 'lexes an instruction with a newline after the name' do lex_stringio("").should == [ diff --git a/spec/oga/xml/parser/processing_instruction_spec.rb b/spec/oga/xml/parser/processing_instruction_spec.rb index 32b9462..e0ad6d9 100644 --- a/spec/oga/xml/parser/processing_instruction_spec.rb +++ b/spec/oga/xml/parser/processing_instruction_spec.rb @@ -32,4 +32,11 @@ describe Oga::XML::Parser do @node.text.should == ' bar ' end end + + it 'parses a processing instruction with a namespace prefix' do + node = parse('').children[0] + + node.should be_an_instance_of(Oga::XML::ProcessingInstruction) + node.name.should == 'foo:bar' + end end