Commit Graph

1222 Commits

Author SHA1 Message Date
Yorick Peterse 11e83f911b
Try to install openjdk for JRuby
This is necessary so "javac" is available.
2017-11-02 14:07:51 +01:00
Yorick Peterse dea9bafee1
Use Ragel without a version
Apparently on some platforms (e.g. the JRuby build) 6.9 breaks things.
2017-11-02 13:24:13 +01:00
Yorick Peterse 9cfd628b55
Install build-base on Alpine
This is necessary to get programs such as "make".
2017-11-02 13:13:57 +01:00
Yorick Peterse 54e3115607
Bundle without nproc on CI
nproc is in coreutils which isn't installed by default. Since the
Gemfile is so small there's no real benefit to using -jX anyway.
2017-11-02 12:56:53 +01:00
Yorick Peterse 794291990e
Use ragel 6.9-r0
Maybe this will work, because apparently just using "ragel=6.9" refuses
to install.
2017-11-02 12:41:46 +01:00
Yorick Peterse de2166eb40
Don't use sudo for Alpine 2017-11-02 12:29:47 +01:00
Yorick Peterse b248cc7c0f
Updated Appveyor config 2017-11-02 12:21:02 +01:00
Yorick Peterse e811b511b0
Fixed the GitLab CI YAML 2017-11-02 02:39:40 +01:00
Yorick Peterse 5d1d7fd1d8
Move to GitLab and GitLab CI 2017-11-02 02:13:00 +01:00
Yorick Peterse f85869ecab
Release 2.11 2017-09-07 00:11:24 +02:00
Loic Nageleisen 39bf7ffaeb Silence method redefinition warnings
As the community progressively moves to a useful practice of enabling
ruby warnings on tests, knowingly redefining a method produces a
distracting warning that has to be special-cased when running automated
tests. We thus skip dynamic definitions of methods we know will be
redefined right after.
2017-09-07 00:03:36 +02:00
Loic Nageleisen 151788abad Silence uninitialized variable warnings
As the community progressively moves to a useful practice of enabling
ruby warnings on tests, assigning an instance variable before use becomes
a necessary practice. Here we set some variables at initialization that
were previously lazily or conditionally set:

- `decoded` is assigned false which seems to make more semantic sense
  than than using nil
- `namespace` is assigned nil, its value being lazily computed later
- `available_namespaces` is assigned nil so as to respect the cache
  invalidation mechanism
2017-09-07 00:03:36 +02:00
hinamiyagk ef1b8d2a28 Fix typo in README 2017-07-11 13:03:52 +02:00
Yorick Peterse d1f46e289c
Reworked the contributing guide a bit
A lot of the stuff in it was rather blunt.
2017-07-07 00:03:48 +02:00
Yorick Peterse 2710976e48
Added note about wanting more patches 2017-07-03 17:58:37 +02:00
Yorick Peterse b5848b07a9
Rename COC.md to make GitHub happy
GitHub only detects CODE_OF_CONDUCT.md.
2017-06-20 17:01:18 +02:00
Yorick Peterse 6f747656b6
Use RSpec 3 expect syntax for tests
This should make it a little bit easier for others to contribute.
2017-06-17 13:52:43 +02:00
Yorick Peterse 8282325569
Don't warn for implicit fallthroughs
This is the result of Ragel output which we can't control.
2017-06-17 13:46:59 +02:00
Yorick Peterse 8dc2318020
Release 2.10 2017-04-18 12:56:24 +02:00
Yorick Peterse 84c4db3e9f
Clean up changes from PR #174 2017-04-18 12:55:11 +02:00
PikachuEXE 4250033ed5 Update CHANGELOG
[ci skip]
2017-04-18 12:51:34 +02:00
PikachuEXE 21b5eeec4b Fix using symbol on Element#attribute alwas getting nil 2017-04-18 12:51:34 +02:00
Yorick Peterse e9953d4212
Release 2.9 2017-02-10 15:59:15 +01:00
Yorick Peterse 673f4a29db
Use HTML5 style closing tags for void elements
This ensures that element tags such as <img> tags don't use a closing />
when documents are parsed as HTML documents.

Fixes #170
2017-02-10 15:24:41 +01:00
Yorick Peterse 131fba7aed
Doctype inherits from Node
This makes it possible to parse documents where a doctype resides in a
node, instead of being located at the root.

Fixes #169
2017-02-10 15:10:30 +01:00
Yorick Peterse b13cfdfea5
Release 2.8 2017-01-04 12:28:37 +01:00
Yorick Peterse 5b4d295912
Nuke old Rubies from CI configuration 2017-01-04 00:12:10 +01:00
Po Shan Cheah c75ca96d22 Ruby 2.4 Fixnum deprecation
In Ruby 2.4, Fixnum is deprecated and the following produces a warning:

$ irb
irb(main):001:0> puts RUBY_VERSION
2.4.0
=> nil
irb(main):002:0> require 'oga'
=> true
irb(main):003:0> Oga.parse_xml('<people><person>Alice</person></people>').css(':nth-child(1)')
/Users/pcheah/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/oga-2.7/lib/oga/xpath/conversion.rb:79: warning: constant ::Fixnum is deprecated
=> NodeSet(Element(name: "people" children: NodeSet(Element(name: "person" children: NodeSet(Text("Alice"))))), Element(name: "person" children: NodeSet(Text("Alice"))))
irb(main):004:0>
$

So oga/xpath/conversion.rb needs to test for Integer instead of Fixnum.

Also, it appears that json 1.8.3 no longer builds under Ruby 2.4, so the gemfile has to be upgraded to json 2.0.
2017-01-03 21:38:04 +01:00
Yorick Peterse f5370c35d2
Release 2.7 2016-09-27 11:54:27 +02:00
Yorick Peterse e0e0687dc2
Generating closing element & Doctype XML
This commit fixes two problems:

1. Doctypes introducing too many newlines
2. Elements with siblings and a common parent not being closed properly

== Doctypes

When generating the XML for a doctype the XML::Generator class would
append a trailing newline. This however meant that if the next text node
was also a newline you'd now have two newlines. In previous versions of
Oga this worked because the old XML generation code would call
String#strip on the XML to add after the doctype.

To support this in the new version we perform a lookahead in
XML::Generator#on_doctype to remove any trailing newlines added by this
method in case the first child node is a newline text node.

== Closing Elements

When an element has a sibling following it _and_ does not have any child
nodes it would not be closed properly when generating XML. This is due
to the "until next_node = ..." expression evaluating to true, thus never
executing its body.

There's probably some way to work around this by using the "loop"
method, but considering it's 02:09 I think the current approach is good
enough. Future me will probably hate me for it.
2016-09-27 02:10:16 +02:00
Yorick Peterse 01fa1513f4
Lexing of processing instructions with namespaces
This adds lexing/parsing support for processing instructions that
contain namespace prefixes such as `<?foo:bar ?>`.
2016-09-17 14:51:48 +02:00
Yorick Peterse 116b9b0ceb
Make XmlDeclaration a ProcessingInstruction
This allows Oga to parse documents that contain an XML declaration at a
place other than at the document root. Oga still only assigns the XML
declaration to the document whenever it is at the top-level. This
matches libxml/XML specification behaviour as far as I can tell.
2016-09-17 14:39:07 +02:00
Scott Wheeler d40baf0c72 Add aliases for accessing attributes via [] and []=
This also fixes accessing attributes via symbol name and tests to ensure
that such does not break in the future.
2016-09-14 15:21:46 +03:00
Yorick Peterse b8fd8670df
Release 2.6 2016-09-10 02:50:02 +02:00
Yorick Peterse 38284278d5
Don't process siblings when reaching a root node
When generating XML we should not process the siblings of a root node.
Doing so results in invalid XML being returned (due to siblings not
being children of the root node).

Not processing the siblings in this case also prevents the siblings loop
from getting stuck. To explain what's happening, let's assume we're
using the following document tree:

    Document
      |_ Text
      |_ Element

Now let's say we take the Text node and call "to_xml" on it. When we
start the loop we'll run into the following code:

    if child_node = children && current.children[0]
      current = child_node
    else

Here the if statement will evaluate to false because a Text node doesn't
have any child nodes, as such we enter the else branch. We now reach the
following code:

    until next_node = current.is_a?(Node) && current.next

A Text node is a descendant of Node and it happens to have another node
(the Element node) as the next sibling. As a result we enter the `until`
loop's body. We now run into this code:

    if current.is_a?(Node) && current != @start
      current = current.parent
    end

Here `current` is still our Text node and it is the @start node. As a
result the `current` re-assignment won't be evaluated.

Next we run into the following:

    after_element(current, output) if current.is_a?(Element)

    break if current == @start

The first line will not evaluate because `current` is still the `Text`
node.  The `break` *will* evaluate because `current` is the same as
@start.

This will then lead to the following code being executed:

    current = next_node

Here `next_node` is the next sibling of the Text node, which in the
above example is the Element node.

Because all of the above runs in a `while` loop we'll at some point end
up again at the start of the `until` loop. At this point the `current`
variable contains an `Element`. Because this node does *not* have a node
following it we'll once again enter the `until` loop's body.

This loop will now get stuck because `current` is a Node, it's not the
same as @start, thus `current` is set to its parent (the Document),
which also isn't the same as @start.

On the next iteration this loop will break because `current` is no
longer a node. However, because a Document _does_ have child nodes the
whole process of traversing children/siblings will keep repeating itself
forever.

To work around this we now use the following statement:

    if child_node = children && current.children[0]
      ...
    elsif current == @start
      after_element(current, output) if current.is_a?(Element)

      break
    else
      until next_node = current.is_a?(Node) && current.next
      ...
    end

This prevents processing of any siblings once we have reached the root
node, in turn preventing the loop getting stuck forever.

I'm willing to bet there are probably a few more edge cases, but I can't
think of any others at the moment.

Fixes #161
2016-09-10 02:49:05 +02:00
Yorick Peterse 7aa34fd192
Removed max width from the YARD output
YARD apparently switched layout to something that doesn't like this, so
let's just get rid of it.
2016-09-06 22:42:57 +02:00
Yorick Peterse 7a8220ae78
Remove unnecessary use of Object#send 2016-09-06 22:37:30 +02:00
Yorick Peterse a6cd19933d
Fixed some YARD markup in XML::Generator 2016-09-06 22:32:10 +02:00
Yorick Peterse dd554f31e7
Release 2.5 2016-09-06 22:30:50 +02:00
Yorick Peterse 68f1f9f660
Relax parsing of XML doctypes
This allows the parser to parse doctypes that contain a mixture of
names, public IDs, inline rules, etc.

Fixes #159
2016-09-06 22:25:22 +02:00
Yorick Peterse e58a41f711
Release 2.4 2016-09-04 21:16:11 +02:00
Yorick Peterse 5a58b14137
Use static variables for Node#previous/#next
Instead of calculating the previous/next node on the fly this data is
now set automatically whenever a node is stored in a NodeSet with an
owner. While this introduces some overhead and complexity when adding or
removing nodes from a NodeSet, it greatly reduces the runtime overhead
of calling Node#previous or Node#next.
2016-09-04 21:07:35 +02:00
Yorick Peterse dd138981f6
Generate XML without relying on recursion
While using recursion is an easy way of generating XML it can lead to
the call stack overflowing when serialising documents with lots of
nested nodes.

Generally there are two ways of working around this:

1. Use an explicit stack (e.g. an array or a queue of sorts) instead of
   relying on the call stack.
2. Use an algorithm that doesn't use a stack at all (e.g. Morris
   traversal).

This commit introduces the XML::Generator class which can serialize
documents back to XML without using a stack at all. This class takes
advantage of XML nodes having access to not only their child nodes, but
also their siblings and their parents.

All XML serialisation logic now resides in the XML::Generator class. In
turn the various "to_xml" methods just use this class and serialize
everything starting at "self".
2016-09-04 19:19:00 +02:00
Yorick Peterse 9ac16e2e4f
Fixed index check in Node#next
An index can/should never be equal the length of a NodeSet, thus we
should use "<" here instead of "<=".
2016-09-03 23:56:55 +02:00
Yorick Peterse de85784097
Release 2.3 2016-07-13 22:44:42 +02:00
Erik Michaels-Ober dca9efb3b1
Change build order to optimize build speed 2016-07-13 22:34:31 +02:00
Erik Michaels-Ober e9073b88c5 Test against Ruby 2.3 2016-07-13 09:12:59 -07:00
Erik Michaels-Ober 3a89dcffab
Remove Parser#reset and PullParser#reset 2016-07-13 17:19:42 +02:00
Erik Michaels-Ober c431c2b004
Lock json dependency to ~> 1.8 on Windows Ruby 1.9 2016-07-13 17:19:42 +02:00
Erik Michaels-Ober 59d2b8c2bc
Remove call to reset_native in Lexer#lex 2016-07-13 17:19:42 +02:00