Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-26229 restore - parser improvements (repetitions and skipped tags)

  • Loading branch information...
commit 5539e698629ad9c8ec2e2c20467958c9f8ef0640 1 parent d911c72
@stronk7 stronk7 authored
View
11 backup/util/xml/parser/processors/simplified_parser_processor.class.php
@@ -104,13 +104,18 @@ public function process_chunk($data) {
$alltagswhitespace = false;
continue;
}
+
// If the path including the tag name matches another selected path
- // (registered or parent) delete it, another chunk will contain that info
+ // (registered or parent) and is null or begins with linefeed, we know it's part
+ // of another chunk, delete it, another chunk will contain that info
if ($this->path_is_selected($path . '/' . $key) ||
$this->path_is_selected_parent($path . '/' . $key)) {
- unset($data['tags'][$key]);
- continue;
+ if (!isset($value['cdata']) || substr($value['cdata'], 0, 1) === "\n") {
+ unset($data['tags'][$key]);
+ continue;
+ }
}
+
// Convert to simple name => value array
$data['tags'][$key] = isset($value['cdata']) ? $value['cdata'] : null;
View
14 backup/util/xml/parser/progressive_parser.class.php
@@ -201,7 +201,12 @@ protected function start_tag($parser, $tag, $attributes) {
// Entering a new inner level, publish all the information available
if ($this->level > $this->prevlevel) {
if (!empty($this->currtag) && (!empty($this->currtag['attrs']) || !empty($this->currtag['cdata']))) {
- $this->topush['tags'][$this->currtag['name']] = $this->currtag;
+ // We always add the last not-empty repetition. Empty ones are ignored.
+ if (isset($this->topush['tags'][$this->currtag['name']]) && trim($this->currtag['cdata']) === '') {
+ // Do nothing, the tag already exists and the repetition is empty
+ } else {
+ $this->topush['tags'][$this->currtag['name']] = $this->currtag;
+ }
}
if (!empty($this->topush['tags'])) {
$this->publish($this->topush);
@@ -233,7 +238,12 @@ protected function end_tag($parser, $tag) {
// Ending rencently started tag, add value to current tag
if ($this->level == $this->prevlevel) {
$this->currtag['cdata'] = $this->postprocess_cdata($this->accum);
- $this->topush['tags'][$this->currtag['name']] = $this->currtag;
+ // We always add the last not-empty repetition. Empty ones are ignored.
+ if (isset($this->topush['tags'][$this->currtag['name']]) && trim($this->currtag['cdata']) === '') {
+ // Do nothing, the tag already exists and the repetition is empty
+ } else {
+ $this->topush['tags'][$this->currtag['name']] = $this->currtag;
+ }
$this->currtag = array();
}
View
3  backup/util/xml/parser/simpletest/fixtures/test4.xml
@@ -106,6 +106,9 @@
<name>4</name><!-- Only last will be processed. We don't allow repeated final tags in our parser -->
<value>4</value>
<value>5</value><!-- Only last will be processed. We don't allow repeated final tags in our parser -->
+ <value>
+
+ </value><!-- If one tag already is set and the repeated is empty, the original value is kept -->
</othertest>
</glossary>
</activity>
Please sign in to comment.
Something went wrong with that request. Please try again.