• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / storage / 24215194021

09 Apr 2026 09:53PM UTC coverage: 63.259% (-17.6%) from 80.843%
24215194021

Pull #1000

github

web-flow
Merge 434cd89fa into 41cfe7541
Pull Request #1000: feat: intro vitest & split units

3465 of 7093 branches covered (48.85%)

Branch coverage included in aggregate %.

2 of 12 new or added lines in 1 file covered. (16.67%)

2655 existing lines in 92 files now uncovered.

13417 of 19594 relevant lines covered (68.48%)

72.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.57
/src/http/plugins/xml.ts
1
import accepts from '@fastify/accepts'
2
import { FastifyInstance } from 'fastify'
3
import fastifyPlugin from 'fastify-plugin'
4
import xml from 'xml2js'
5

6
type XmlParserOptions = { disableContentParser?: boolean; parseAsArray?: string[] }
7
type RequestError = Error & { statusCode?: number }
8

9
function forcePathAsArray(node: unknown, pathSegments: string[]): void {
26✔
10
  if (pathSegments.length === 0 || node === null || node === undefined) {
2!
11
    return
×
12
  }
13

14
  if (Array.isArray(node)) {
2!
15
    node.forEach((item) => forcePathAsArray(item, pathSegments))
×
16
    return
×
17
  }
18

19
  if (typeof node !== 'object') {
2!
20
    return
×
21
  }
22

23
  const [current, ...rest] = pathSegments
2✔
24
  const currentRecord = node as Record<string, unknown>
2✔
25

26
  if (!(current in currentRecord)) {
2!
27
    return
×
28
  }
29

30
  if (rest.length === 0) {
2✔
31
    const value = currentRecord[current]
1✔
32
    if (value !== undefined && !Array.isArray(value)) {
1!
33
      currentRecord[current] = [value]
1✔
34
    }
35
    return
1✔
36
  }
37

38
  forcePathAsArray(currentRecord[current], rest)
1✔
39
}
40

41
export const xmlParser = fastifyPlugin(
1✔
42
  async function (fastify: FastifyInstance, opts: XmlParserOptions) {
2,827✔
43
    fastify.register(accepts)
3✔
44

45
    if (!opts.disableContentParser) {
3!
46
      fastify.addContentTypeParser(
3✔
47
        ['text/xml', 'application/xml'],
48
        { parseAs: 'string' },
49
        (_request, body, done) => {
86✔
50
          if (!body) {
2!
UNCOV
51
            done(null, null)
×
UNCOV
52
            return
×
53
          }
54

9✔
55
          xml.parseString(
2✔
56
            body,
57
            {
58
              explicitArray: false,
59
              trim: true,
60
              valueProcessors: [xml.processors.parseNumbers, xml.processors.parseBooleans],
61
            },
62
            (err: Error | null, parsed: unknown) => {
9✔
63
              if (err) {
2✔
64
                const parseError: RequestError = new Error(`Invalid XML payload: ${err.message}`)
1✔
65
                parseError.statusCode = 400
1✔
66
                done(parseError)
1✔
67
                return
1✔
68
              }
69

8✔
70
              if (parsed && opts.parseAsArray?.length) {
1!
71
                opts.parseAsArray.forEach((path) => {
1✔
72
                  if (!path) {
1!
73
                    return
×
74
                  }
75
                  forcePathAsArray(parsed, path.split('.'))
1✔
76
                })
77
              }
78

79
              done(null, parsed)
1✔
80
            }
81
          )
82
        }
83
      )
84
    }
85

86
    fastify.addHook('preSerialization', async (req, res, payload) => {
3✔
87
      const accept = req.accepts()
2✔
88

89
      const acceptedTypes = ['application/xml', 'text/html']
2✔
90

91
      if (acceptedTypes.some((allowed) => accept.types(acceptedTypes) === allowed)) {
3✔
92
        res.serializer((payload) => payload)
1✔
93

94
        const xmlBuilder = new xml.Builder({
1✔
95
          renderOpts: {
96
            pretty: false,
97
          },
98
        })
99
        const xmlPayload = xmlBuilder.buildObject(payload)
1✔
100
        res.type('application/xml')
1✔
101
        res.header('content-type', 'application/xml; charset=utf-8')
1✔
102
        return xmlPayload
1✔
103
      }
104

×
105
      return payload
1✔
106
    })
107
  },
108
  { name: 'xml-parser' }
109
)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc