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

supabase / storage / 25163834703

30 Apr 2026 11:52AM UTC coverage: 71.924% (+0.03%) from 71.891%
25163834703

Pull #1071

github

web-flow
Merge 416c2b114 into d25a84735
Pull Request #1071: fix: iceberg container and acceptance tests

3576 of 5528 branches covered (64.69%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

3883 existing lines in 165 files now uncovered.

7465 of 9823 relevant lines covered (76.0%)

392.79 hits per line

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

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

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

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

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

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

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

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

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

39
  forcePathAsArray(currentRecord[current], rest)
14✔
40
}
41

42
export const xmlParser = fastifyPlugin(
27✔
43
  async function (fastify: FastifyInstance, opts: XmlParserOptions) {
44
    fastify.register(accepts)
2,907✔
45

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

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

73
              if (parsed && opts.parseAsArray?.length) {
9!
74
                opts.parseAsArray.forEach((path) => {
9✔
75
                  if (!path) {
14!
76
                    return
×
77
                  }
78
                  forcePathAsArray(parsed, path.split('.'))
14✔
79
                })
80
              }
81

82
              done(null, parsed)
9✔
83
            }
84
          )
85
        }
86
      )
87
    }
88

89
    fastify.addHook('preSerialization', async (req, res, payload) => {
2,907✔
90
      const accept = req.accepts()
123✔
91

92
      const acceptedTypes = ['application/xml', 'text/html']
123✔
93

94
      if (acceptedTypes.some((allowed) => accept.types(acceptedTypes) === allowed)) {
124✔
95
        res.serializer((payload) => payload)
122✔
96

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

108
      return payload
1✔
109
    })
110
  },
111
  { name: 'xml-parser' }
112
)
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