Skip to content

Commit

Permalink
Fix issues (#365)
Browse files Browse the repository at this point in the history
* WIP

* Update for clang-format

* Update clang-format rules
  • Loading branch information
ohler55 authored Dec 25, 2024
1 parent cd85115 commit 9d0b4ee
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 12 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: clang-format Check

on:
push:
branches:
- develop
- master
paths:
- ".clang-format"
- ".github/workflows/clang-format.yml"
Expand All @@ -27,6 +24,6 @@ jobs:
- uses: actions/checkout@v4

- name: Run clang-format style check
uses: jidicula/clang-format-action@v4.11.0
uses: jidicula/clang-format-action@v4.13.0
with:
clang-format-version: 16
clang-format-version: 19
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All changes to the Ox gem are documented here. Releases follow semantic versioning.

## [2.14.19] - 2024-12-25

### Fixed

- Code cleanup in sax.c to close issue #363.

- Updated the dump options documentation to `:with_xml` option to resolve #352.

- Updated the sax tests to pass to resolve #335.

- Element#replace_text on nil `@nodes` no longer fails. Closes #364.

## [2.14.18] - 2024-03-21

### Fixed
Expand Down
9 changes: 9 additions & 0 deletions ext/ox/ox.c
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,9 @@ static void parse_dump_options(VALUE ropts, Options copts) {
* :strict
* - _:strict_ - raise an NotImplementedError if an undumpable object is encountered
* - _:tolerant_ - replaces undumplable objects with nil
* - *:with_dtd* [true|false|nil] include DTD in the dump
* - *:with_instruct* [true|false|nil] include instructions in the dump
* - *:with_xml* [true|false|nil] include XML prolog in the dump
*
* Note that an indent of less than zero will result in a tight one line output
* unless the text in the XML fields contain new line characters.
Expand Down Expand Up @@ -1310,6 +1313,9 @@ static VALUE dump(int argc, VALUE *argv, VALUE self) {
* :strict
* - _:strict_ - raise an NotImplementedError if an undumpable object is encountered
* - _:tolerant_ - replaces undumplable objects with nil
* - *:with_dtd* [true|false|nil] include DTD in the dump
* - *:with_instruct* [true|false|nil] include instructions in the dump
* - *:with_xml* [true|false|nil] include XML prolog in the dump
*
* Note that an indent of less than zero will result in a tight one line output
* unless the text in the XML fields contain new line characters.
Expand All @@ -1331,6 +1337,9 @@ static VALUE to_xml(int argc, VALUE *argv, VALUE self) {
* :strict
* - _:strict_ - raise an NotImplementedError if an undumpable object is encountered
* - _:tolerant_ - replaces undumplable objects with nil
* - *:with_dtd* [true|false|nil] include DTD in the dump
* - *:with_instruct* [true|false|nil] include instructions in the dump
* - *:with_xml* [true|false|nil] include XML prolog in the dump
*
* Note that an indent of less than zero will result in a tight one line output
* unless the text in the XML fields contain new line characters.
Expand Down
6 changes: 5 additions & 1 deletion ext/ox/sax.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,11 @@ static char read_element_end(SaxDrive dr) {
} else {
snprintf(msg, sizeof(msg) - 1, "%selement '%s' closed but not opened", EL_MISMATCH, dr->buf.str);
ox_sax_drive_error_at(dr, msg, pos, line, col);
name = str2sym(dr, dr->buf.str, dr->buf.tail - dr->buf.str - 2, 0);
if ('\x00' == *dr->buf.tail) {
name = str2sym(dr, dr->buf.str, dr->buf.tail - dr->buf.str - 1, 0);
} else {
name = str2sym(dr, dr->buf.str, dr->buf.tail - dr->buf.str - 2, 0);
}
if (dr->has_start_element && 0 >= dr->blocked &&
(NULL == h || ActiveOverlay == h->overlay || NestOverlay == h->overlay)) {
VALUE args[1];
Expand Down
3 changes: 1 addition & 2 deletions ext/ox/sax_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ typedef struct _checkPt {
char c;
} *CheckPt;

#define CHECK_PT_INIT \
{ -1, 0, 0, 0, '\0' }
#define CHECK_PT_INIT {-1, 0, 0, 0, '\0'}

extern void ox_sax_buf_init(Buf buf, VALUE io);
extern int ox_sax_buf_read(Buf buf);
Expand Down
6 changes: 5 additions & 1 deletion lib/ox/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ def text
def replace_text(txt)
raise 'the argument to replace_text() must be a String' unless txt.is_a?(String)

@nodes.clear
if !instance_variable_defined?(:@nodes) or @nodes.nil?
@node = []
else
@nodes.clear
end
@nodes << txt
end

Expand Down
20 changes: 20 additions & 0 deletions test/sax/sax_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,26 @@ def test_sax_open_close_element
])
end

def test_sax_last_element_closed_not_opened
Ox.default_options = $ox_sax_options
parse_compare(%{</top>},
[
[:error, "Start End Mismatch: element 'top' closed but not opened", 1, 1],
[:start_element, :top],
[:end_element, :top]
])
end

def test_sax_last_unnamed_element_closed_not_opened
Ox.default_options = $ox_sax_options
parse_compare(%{</>},
[
[:error, "Start End Mismatch: element '' closed but not opened", 1, 1],
[:start_element, :''],
[:end_element, :'']
])
end

def test_sax_empty_element
Ox.default_options = $ox_sax_options
parse_compare(%{ <top> </top>},
Expand Down
3 changes: 0 additions & 3 deletions test/sax/smart_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ def test_not_opened_nested
html = '<h1 class=a_class>A header</div> here</h1>'
smart_parse_compare(html,
[[:start_element, :h1],
[:error, 'Unexpected Character: attribute value not in quotes', 1, 11],
[:attr, :class, 'a_class'],
[:text, 'A header'],
[:error, "Start End Mismatch: element 'div' closed but not opened", 1, 27],
Expand All @@ -420,7 +419,6 @@ def test_unquoted_slash
html = '<a href=abc/>def</a>'
smart_parse_compare(html,
[[:start_element, :a],
[:error, 'Unexpected Character: attribute value not in quotes', 1, 9],
[:attr, :href, 'abc/'],
[:text, 'def'],
[:end_element, :a]])
Expand All @@ -430,7 +428,6 @@ def test_unquoted_slash_no_close
html = '<a href=abc/>def'
smart_parse_compare(html,
[[:start_element, :a],
[:error, 'Unexpected Character: attribute value not in quotes', 1, 9],
[:attr, :href, 'abc/'],
[:error, 'Not Terminated: text not terminated', 1, 16],
[:text, 'def'],
Expand Down

0 comments on commit 9d0b4ee

Please sign in to comment.