Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: added new parameter to control the xml parsing #687

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
name: CI

on:
push:
branches: [trim-text]
pull_request:
# The branches below must be a subset of the branches above
branches: [trim-text]
schedule:
- cron: '0 2 * * 1' # At 02:00 on Monday

permissions: {}

jobs:
test:
name: Test
timeout-minutes: 15
strategy:
matrix:
os: [ubuntu-latest]
node-version: [18, 20, 21]
include:
- os: macos-latest
node-version: 18 # LTS
- os: windows-latest
node-version: 18 # LTS
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: ${{ matrix.node-version }}
- name: Bootstrap project
run: npm ci --ignore-scripts
- name: Build project
run: npm run --ignore-scripts build
- name: Run tests
run: npm test --ignore-scripts
- name: Coveralls Parallel
uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # tag=v2.2.3
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.os }}-node@${{ matrix.node-version }}
path-to-lcov: ${{ github.workspace }}/coverage/lcov.info
parallel: true

posttest:
name: Post-Test
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finish
uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # tag=v2.2.3
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true

commit-lint:
name: Commit Lint
runs-on: ubuntu-latest
if: ${{ github.event.pull_request }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
with:
fetch-depth: 0
- name: Use Node.js 18
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 18
- name: Bootstrap project
run: npm ci --ignore-scripts
- name: Verify commit linting
run: npx commitlint --from origin/master --to HEAD --verbose

codeql:
name: CodeQL
runs-on: ubuntu-latest
permissions:
# See: https://github.com/github/codeql-action/blob/008b2cc71c4cf3401f45919d8eede44a65b4a322/README.md#usage
security-events: write
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1
- name: Initialize CodeQL
uses: github/codeql-action/init@8a470fddafa5cbb6266ee11b37ef4d8aae19c571 # v3.24.6
with:
languages: 'javascript'
config-file: ./.github/codeql/codeql-config.yaml
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@8a470fddafa5cbb6266ee11b37ef4d8aae19c571 # v3.24.6
6 changes: 5 additions & 1 deletion src/parser/xmlHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class XMLHandler {
* @param {Object} [options.date]
* @param {Object} [options.date.timezone]
* @param {boolean} [options.date.timezone.enabled]
* @param {boolean} [options.trimText]
*/
constructor(schemas, options) {
this.schemas = schemas || {};
Expand All @@ -43,6 +44,7 @@ class XMLHandler {
this.options.date = this.options.date || {};
this.options.date.timezone = this.options.date.timezone || {};
this.options.date.timezone.enabled = typeof this.options.date.timezone.enabled === 'boolean' ? this.options.date.timezone.enabled : true;
this.options.trimText = typeof this.options.trimText === 'boolean' ? this.options.trimText : true;
}

jsonToXml(node, nsContext, descriptor, val) {
Expand Down Expand Up @@ -709,7 +711,9 @@ class XMLHandler {
};

p.ontext = function(text) {
text = text && text.trim();
if (self.options.trimText) {
text = text && text.trim();
}
if (!text.length)
return;

Expand Down